Is the array sorted in any way? If it's completely un-sorted, you kinda don't have any options but to do a O(n) search.
If it is sorted, you could quite easily write yourself a quick binary search algorithm, while it isn't the fastest searcher in the world, it is better than looping through all the items. OR you could just be really lazy, and utilise the contains() Java function off the myArray. http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html#contains(java.lang.Object) Could be lots of fun since it's a 2d array. You may want to look into alternative data structures for your data if it's a 2d array and you are finding it hard to manage. No reason at all you can't leverage Java Collections. Mark On 6/3/05, Chad Renando <[EMAIL PROTECTED]> wrote: > 'morning all. > > What would be the best way to find a particular value in an array? > Ideally, I would like to query my array to get a certain value where a > condition is true, sort of like > > SELECT MyArray[1][5] > FROM MyArray > WHERE MyArray[1][2] = "Something" > > The altrnative is to loop through the array and grab the value on the > way through, but I am thinking I will take a performance hit, > particularly as I am doing this within a loop already... > > <cfloop index="i" from="1" to="#ArrayLen(MyArray)#"> > <cfif MyArray[1][2] = "Something"><cfset MyValue=1></cfif> > </cfloop> > > Cheers, > > Chad > who uses band names like Rammstein in general conversation 'cause it > just sounds cool -- E: [EMAIL PROTECTED] W: www.compoundtheory.com ICQ: 3094740 --- You are currently subscribed to cfaussie as: [email protected] To unsubscribe send a blank email to [EMAIL PROTECTED] Aussie Macromedia Developers: http://lists.daemon.com.au/
