How to find index of STRING array in Java from a given value?

前端 未结 13 2088
谎友^
谎友^ 2020-12-08 02:11

I wanted to know if there\'s a native method in array for Java to get the index of the table for a given value ?

Let\'s say my table contains these strings :

<
13条回答
  •  暖寄归人
    2020-12-08 02:53

    I had an array of all English words. My array has unique items. But using…

    Arrays.asList(TYPES).indexOf(myString);
    

    …always gave me indexOutOfBoundException.

    So, I tried:

    Arrays.asList(TYPES).lastIndexOf(myString);
    

    And, it worked. If your arrays don't have same item twice, you can use:

    Arrays.asList(TYPES).lastIndexOf(myString);
    

提交回复
热议问题