Java中的IntStream different()方法
distinct()Java中IntStream类中的方法返回一个由该流的不同元素组成的流。
语法如下
IntStream distinct()
假设我们在流中包含以下元素。其中一些重复
IntStream intStream = IntStream.of(10, 20, 30, 20, 10, 50, 80, 90, 100, 80);
若要获取不同的元素,请使用IntStreamdistinct()方法。
以下是distinct()在Java中实现IntStream方法的示例
示例
import java.util.stream.IntStream;
public class Demo {
public static void main(String[] args) {
IntStream intStream = IntStream.of(10, 20, 30, 20, 10, 50, 80, 90, 100, 80);
System.out.println("显示不同的元素:");
intStream.distinct().forEach(System.out::println);
}
}输出结果
显示不同的元素: 10 20 30 50 80 90 100
热门推荐
1 训练狗狗工作
4 狗狗定点排便训练
5 狗狗训练吠叫
6 狗狗尿垫训练
7 狗狗训练座
8 狗狗训练攻略
9 狗狗训练记
10 做训练狗狗
11 狗狗训练词
12 狗狗谢谢怎么训练
13 狗狗训练如厕
14 狗狗太凶怎么训练
15 狗狗训练它
16 狗狗克制训练
17 训练基地狗狗
18 怎么样训练狗狗大小硬