Android - Check whether a value exist in an Array

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

    If you are going to check it a lot you may find it more efficient to use a HashSet:

    String[] bob = { "this", "is", "a", "really", "silly", "list" };
    Set silly = new HashSet(Arrays.asList(bob));
    boolean isSilly = silly.contains("silly");
    

提交回复
热议问题