Streams – collect() operation
class Test { public static void main(String[] args) { List<String> words = new ArrayList<>(Arrays.asList(“Hello”, “World”, “of”, “Java!”)); String result = words.stream().collect(Collectors.joining()); System.out.println(result); String resultWithDelimiters = words.stream().collect(Collectors.joining(“-“)); // delimiter System.out.println(resultWithDelimiters); String resultWithDelimitersAndPrefixAndSuffix = words.stream().collect(Collectors.joining(“-“, “(“, “)”)); // delimiter, prefix, suffix System.out.println(resultWithDelimitersAndPrefixAndSuffix); } } Output: HelloWorldofJava! Hello-World-of-Java! (Hello-World-of-Java!) class Test { public static void main(String[] args) {…
Read More Streams – collect() operation