ArrayList contains case sensitivity

前端 未结 19 1766
故里飘歌
故里飘歌 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 18:09

    You can use IterableUtils and Predicate from collections4 (apache).

    List pformats= Arrays.asList("Test","tEst2","tEsT3","TST4");
    
    Predicate predicate  = (s) -> StringUtils.equalsIgnoreCase(s, "TEST");
    if(IterableUtils.matchesAny(pformats, predicate)) {
        // do stuff
    }
    

    IterableUtils(collections4): org.apache.commons.collections4.IterableUtils.html

提交回复
热议问题