Saturday, February 20, 2010

Index Of Pics/party How Do You Find The Index Of An Element In An Int[]? JAVA?

How do you find the index of an element in an int[]? JAVA? - index of pics/party

I have a series of numbers and want the index to find a row ..

I have tried Array.indexOf (int), but said he could not find the icon. Is there an easy way to do this, or I have to write a loop?

2 comments:

Anonymous said...

You need to write a loop. When you return to the value of the indices), want to be found (with a normal table, then a parent is probably not using the correct structure.

Anonymous said...

Yes, you need a change like this to be done.

int index = -1;

for (int i = 0, i \\ \\ \\ \\ \\ \\ \\ \\ u0026lt; array.length; i + +)
(
if (array [i] == \\ \\ \\ \\ \\ \\ \\ \\ u0026lt the number>)
(
index = i;
break;
)
)

In the end, or the index is -1 or is not found, and the actual rate of the matrix.

Of course you can not use this cycle a static helper method and put it in a class by itself. Then you call the static method if you want to find the value of the index. You can even call the method indexOf if desired.

I hope that helps.

Post a Comment