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.
Page Index Toggle Pages: 1
array search (Read 473 times)
array search
May 2nd, 2008, 4:11pm
Is there any method for searching in an array?

I mean something similar to string.indexOf()
Re: array search
Reply #1 - May 2nd, 2008, 6:16pm
loop through the array and compare it's content to whatever you're trying to find:

int[] test = { 1,2,3,5,7,4,23,64};
for (int i=0; i<test.length; i++){
 if (test[i]==5){
   println("found 5 at index position: "+i);

Re: array search
Reply #2 - May 2nd, 2008, 8:17pm
Its much easier: http://www.exampledepot.com/egs/java.util/coll_FindInArray.html
Note, that the array need to be sorted for this solution.
Re: array search
Reply #3 - May 3rd, 2008, 9:04am
Thank you very much. I solved my problem using some code similar to sgsrules´ one.
Page Index Toggle Pages: 1