核心代码
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class ForeachDemo {
public static void main(String[] args) {
List<String> list = Arrays.asList("111", "222", "3333", "222");
list.forEach(System.out::println);
List<String> collect = list.stream().collect(Collectors.toList());
System.out.println(collect);
Set<String> collect1 = list.stream().collect(Collectors.toSet());
System.out.println(collect1);
LinkedList<String> collect2 = list.stream().collect(Collectors.toCollection(LinkedList::new));
System.out.println(collect2);
}
}