Android - Check whether a value exist in an Array

前端 未结 5 1287
挽巷
挽巷 2021-02-01 01:24

I have an array named \"bob\" which contains values.

String[] bob = { \"this\", \"is\", \"a\", \"really\", \"silly\", \"list\" };

How can I kno

5条回答
  •  一整个雨季
    2021-02-01 01:34

    Convert the Array to List using static Arrays.asList(T) and check with List.contains(Object) to check if an object exists in the retuned collection.

        String[] bob = { "this", "is", "a", "really", "silly", "list" };
               System.out.println(Arrays.asList(bob).contains("silly"));
    

    Traditional way however would be to iterate over the array and check at each element using equals().

提交回复
热议问题