상세 컨텐츠

본문 제목

[Stream] 스트림직렬처리와 병렬처리 비교

Java

by kwanghyup 2020. 6. 16. 14:03

본문

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

public class ForEachExam02 {

    public static void main(String[] args) {

        List<String> list = new ArrayList<>();
        for (int number = 1; number <= 10 ; number++) {
            list.add("["+number+"]손흥민");
        }

        //직렬처리
        Stream<String> stream = list.stream();
        stream.forEach(ForEachExam02::println);

        System.out.println("\n===============================\n");

        //병렬 처리
        Stream<String> parallelstream = list.parallelStream();
        parallelstream.forEach(ForEachExam02::println);
    }

    public static void println(String e) {
        System.out.println(e + " : " + Thread.currentThread().getName() );
    }

}

 

관련글 더보기

댓글 영역