![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/547d1ba8c7335e6fcb4611acdac0eca6.png#pic_center)
```bash
package java8;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class Stream {
public static void main(String[] args) {
List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd", "", "jkl");
List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
filtered.stream().forEach(x -> System.out.println(x));
List<Integer> numbers = Arrays.asList(3, 2, 2, 3, 7, 3, 5);
List<Integer> squaresList = numbers.stream().map(i -> i * i).distinct().collect(Collectors.toList());
squaresList.stream().forEach(x -> System.out.println(" distinct:" + x));
List<Integer> noDistinctList = numbers.stream().map(i -> i * i).collect(Collectors.toList());
noDistinctList.stream().forEach(x -> System.out.println("no distinct:" + x));
long count = strings.parallelStream().filter(string -> string.isEmpty()).count();
System.out.println("count:" + count);
List<String> strings1 = Arrays.asList("abc", "", "bc", "efg", "abcd", "", "jkl");
List<String> filtered1 = strings1.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
System.out.println("筛选列表: " + filtered1);
String mergedString = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.joining(", "));
System.out.println("合并字符串: " + mergedString);
List<String> items = Arrays.asList("apple", "apple", "banana", "apple", "orange", "banana", "papaya");
Map<String, Long> result = items
.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
System.out.println(result);
}
}