ArrayList contains case sensitivity

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

    For java8

    list.stream().anyMatch(s -> s.equalsIgnoreCase(yourString))

    For < java8

    • as suggested by Aaron J Lang above
    • Or if you know case of your list ( all upper /all lower ) then convert the search string to appropriate case before comparing

提交回复
热议问题