Answers for "java get index of object in list"

0

get index of element java

// if you're too lazy to do anything fancy
// here's a code snippet for ya

// replace 'TYPE' with whatever type your using
// like 'int' or 'String' for example
public static int indexOf(TYPE[] arr, TYPE element)
{
	for (int index = 0; index < arr.length; index++)
    {
    	if (arr[index] == element)
          	return index;
      	else break;
    }
  	
  	// the '-1' is the unique value to
  	// inform you that no element was found
  	return -1;
}
Posted by: Guest on March-12-2022

Code answers related to "java get index of object in list"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language