Collect HashSet / Java 8 / Regex Pattern / Stream API

后端 未结 6 791
日久生厌
日久生厌 2020-12-29 09:42

Recently I change version of the JDK 8 instead 7 of my project and now I overwrite some code snippets using new features that came with Java 8.

final Matcher         


        
6条回答
  •  北海茫月
    2020-12-29 10:35

    What about Pattern.splitAsStream ?

    Stream stream = Pattern.compile(regex).splitAsStream(input);
    

    and then a collector to get a set.

    Set set = stream.map(String::toLowerCase).collect(Collectors.toSet());
    

提交回复
热议问题