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

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

    Use this as a method with x being any number initially. The string y being passed in by console and v is the array to search!

    public static int getIndex(int x, String y, String[]v){
        for(int m = 0; m < v.length; m++){
            if (v[m].equalsIgnoreCase(y)){
                x = m;
            }
        }
        return x;
    }
    

提交回复
热议问题