ArrayList contains case sensitivity

前端 未结 19 1767
故里飘歌
故里飘歌 2020-11-27 17:14

I am currently using the contains method belonging to the ArrayList class for making a search. Is there a way to make this search case insensitive in java? I found that in C

19条回答
  •  时光取名叫无心
    2020-11-27 17:46

    I would make it like so:

    public boolean isStringInList(final List myList, final String stringToFind) {
        return myList.stream().anyMatch(s -> s.equalsIgnoreCase(stringToFind));
    }  
    

提交回复
热议问题