Monday, 15 July 2019

java stream api manupalation for arraylist of integer to comma sepertaed

import java.util.*;
import java.util.stream.Collectors;
class Main {
  public static void main(String[] args) {
   List<String> strings = new LinkedList<>();
     strings.add("Java");strings.add("is");
     strings.add("cool");
     String message = String.join(", ", strings);
     System.out.println(message);

      List<Integer> num = new LinkedList<>();
     num.add(2);
     num.add(5);
     num.add(7);
     String message1 =num.stream().map((gameId)-> gameId.toString()).collect(Collectors.joining(","));
     System.out.println(message1);
     //message returned is: "Java is cool"

  }
}
https://www.baeldung.com/java-string-with-separator-to-list

No comments:

Post a Comment