How to lowercase every element of a collection efficiently?

后端 未结 11 577
走了就别回头了
走了就别回头了 2020-12-02 16:53

What\'s the most efficient way to lower case every element of a List or Set?

My idea for a List:

final List strings = new ArrayList<         


        
11条回答
  •  失恋的感觉
    2020-12-02 17:47

    Using JAVA 8 parallel stream it becomes faster

    List output= new ArrayList<>();
    List input= new ArrayList<>();
    input.add("A");
    input.add("B");
    input.add("C");
    input.add("D");
    input.stream().parallel().map((item) -> item.toLowerCase())
                .collect(Collectors.toCollection(() -> output));
    

提交回复
热议问题