Java List map elements to create new List via Stream

Description

Java List map elements to create new List via Stream

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
   public static void main(String[] args) {
      List<String> lst = Arrays.asList("CSS", "", "HTML", "Java", "Javascript", "demo2s.com");


      List<String> lstRecWithCon = lst.stream().map(s -> s + ":" + s.length()).collect(Collectors.toList());

      System.out.println(lstRecWithCon);

   }//from  w  w  w .  ja  va2 s.c  o  m
}



PreviousNext

Related