Android - Check whether a value exist in an Array

前端 未结 5 1286
挽巷
挽巷 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:55

    You can use List#contains method. For that you need to convert your array to a list. You can use Arrays#asList() method fot that:

    String[] bob = { "this", "is", "a", "really", "silly", "list" };
    
    if (Arrays.asList(bob).contains("silly")) {
        // true
    }
    

提交回复
热议问题