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

前端 未结 13 2101
谎友^
谎友^ 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:55

    An easy way would be to iterate over the items in the array in a loop.

    for (var i = 0; i < arrayLength; i++) {
     // (string) Compare the given string with myArray[i]
     // if it matches store/save i and exit the loop.
    }
    

    There would definitely be better ways but for small number of items this should be blazing fast. Btw this is javascript but same method should work in almost every programming language.

提交回复
热议问题