Convert a for loop to concat String into a lambda expression

后端 未结 5 1692
予麋鹿
予麋鹿 2021-02-03 22:37

I have the following for loop which iterates through a list of strings and stores the first character of each word in a StringBuilder. I would like to know how can

5条回答
  •  死守一世寂寞
    2021-02-03 23:14

    Simple way using method reference :

    List list = Arrays.asList("ABC", "CDE");
    StringBuilder sb = new StringBuilder();
    
    list.forEach(sb::append);
    
    String concatString = sb.toString();
    

提交回复
热议问题