19082 views.
package com.learnbyexamples.streams;
import java.util.regex.Pattern;
import java.util.stream.Stream;
public class E006_SplitStringIntoStream {
public static void main(String[] args) {
//Delimited names
String names = "raja,siva,ram,kumar,vinoth";
//Comma to split the string
Pattern pattern = Pattern.compile(",");
//Spliting names by comma converting into stream
Stream<String> namesStream = pattern.splitAsStream(names);
//Iterate stream using forEach and Print the names.
namesStream.forEach(System.out::println);
}
}