ArrayList contains case sensitivity

前端 未结 19 1768
故里飘歌
故里飘歌 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:55

    If you're using Java 8, try:

    List list = ...;
    String searchStr = ...;
    boolean containsSearchStr = list.stream().filter(s -> s.equalsIgnoreCase(searchStr)).findFirst().isPresent();
    

提交回复
热议问题