find out the index of an element in array:
/** * @author lautturi.com * Java example: how to get the element index in java array */ import java.util.*; public class Lautturi { public static void main(String[] args) { String[] strArray = {"java","python","perl","js","perl","c","go"}; String str = "js"; int idx = Arrays.asList(strArray).indexOf(str); System.out.println("The index of js element is "+idx); } }
output:
The index of js element is 3