Integer myArray[]= {12,23,10,22,10}; System.out.println(Arrays.asList(myArray).indexOf(23));
will solve the problem
Arrays.asList(myArray).indexOf(23) this search on objects, so we must use the object type int , since int is a primitive type.
String myArray[]= {"12","23","10","22","10"}; Arrays.asList(myArray).indexOf("23");
In the second case, this will work because String is an object.
When we define a List , define it as List<String> or List<Integer> . therefore primitives are not used in List . Then Arrays.asList(myArray).indexOf("23") find the index of the equivalent object.
source share