+ 6
I want to know how to find the index number (position) of certain element of an array in java.
int [] i = {6,5,8,9,2,3} I just want to know how can I know the index number of any element of i like 9.
4 Antworten
+ 5
public int getArrayIndex(int[] arr,int value) {
int k=0;
for(int i=0;i<arr.length;i++)
{ if(arr[i]==value)
{ k=i; break; }
} return k; }
//Call this method and pass two parameters that are Array and value
int indexNum = getArrayIndex(i,9); //here , u hv to pass these parameters to know the index of "9" in array "i"
+ 6
I know but I want to know the method of how I can get the index number of any element of an array by using any method.
+ 6
thanks I think this is what I want
+ 4
it will be 1 less than the actual position bcz the in java we start counting index from 0
so i [0] is 6
i [1] is 5
i [3] is 9 //ie index of 9 is 3 in the above code