We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › looking for position in array
Page Index Toggle Pages: 1
looking for position in array (Read 245 times)
looking for position in array
Mar 21st, 2009, 10:14pm
 
hi

when objects are stored in array each position is given an index number. Is there a way to pass an object that sits in an array and get its index in return?

thanks
Re: looking for position in array
Reply #1 - Mar 22nd, 2009, 12:30am
 
Yes, just walk the array and stop if/when you find it... Smiley
If time is critical, you can put the objects in an HashMap, with the objects as key and the indexes as value, although I am not sure it is then still interesting to maintain the array...
Or... come to think of it, just use Arrays.binarySearch!
Page Index Toggle Pages: 1