Wednesday, December 7, 2016

Comma separated

     
     
This code is taken from the presentation of Java One keynote. The link of which is posted below the code.


Problem: Print the name of your five friends stored in an ArrayList in upper case comma separated.


import java.util.*;
import static java.util.stream.Collectors.*;

public class ArrayListExamples {
  public static void main(String[]args){
 
  Listnames = Arrays.asList("Tom","Jerry","Jane","Jack");
 
  //print the names in uppercase, comma separated
 
System.out.println(
names.stream()
.map(String::toUpperCase)
             .collect(joining(",")));
  }
  }
 ----------------------------------------------------------------------------------------------- 





No comments: