Studying Java 8 (Collector / Collectors)

So it's Collector / Collectors. It seems to be used when you want to extract the result of Stream while processing it. Below is a sample.

import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 *Studying Collectors
 * @author komikcomik
 *
 */
public class CollectorsHello {

	public static void main(String[] args) {

		//The stream of the character string is combined into a String, and the delimiter, the first character, and the last character are added at that time.
		Stream<String> s = Stream.of("1", "2", "3", "4", "5", "6", "7");
		String ss = s.collect(Collectors.joining("-", "lead", "end"));
		System.out.println(ss);

	}
}

The execution result is as follows.

First 1-2-3-4-5-6-7 end

Recommended Posts

Studying Java 8 (Collector / Collectors)
Studying Java ―― 3
Studying Java ―― 9
Studying Java ―― 4
Studying Java -5
Studying Java ―― 1
Studying Java # 0
Studying Java ―― 8
Studying Java ②
Studying Java ―― 7
Studying Java ―― 2
Studying Java ①
Studying Java -10
Studying Java 8 (Optional)
Studying java9 (jShell)
Studying Java 8 (Stream)
[Java] Stream Collectors notes
Studying Java 8 (see method)
Studying Java 8 (see constructor)
Studying Java ~ Part 8 ~ Cast
Studying Java 8 (lambda expression)
Studying Java # 6 (How to write blocks)
Java
Studying Java 8 (StaticIF and Default methods)
Studying Java 8 (String Joiner and join)
Java
Studying java9 (dropWhile, takeWhile and Stream.ofNullable)
Studying Java 8 (date API in java.time package)
[# 1 Java] Basics of Java-Major premise before studying-
Studying how to use the constructor (java)
Studying java (Basic Information Technology Engineer Examination)