Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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;
}
Source by howtodoinjava.com #
 
PREVIOUS NEXT
Tagged: #index #element #java
ADD COMMENT
Topic
Name
7+5 =