How to find the index of an element in an int array?

前端 未结 19 1353
南方客
南方客 2020-11-27 02:56

How can I find an index of a certain value in a Java array of type int?

I tried using Arrays.binarySearch on my unsorted array, it only som

19条回答
  •  無奈伤痛
    2020-11-27 03:01

    You could convert it to a list, then use the indexOf method:

    Array.asList(array).indexOf(1); 
    

    http://download.oracle.com/javase/1.5.0/docs/api/java/util/Arrays.html#asList(T...) http://download.oracle.com/javase/1.5.0/docs/api/java/util/List.html#indexOf(java.lang.Object)

提交回复
热议问题