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
热门推荐
10 祝福语写给自己的简短
11 商业mc祝福语大全简短
12 孩子16岁祝福语简短
13 生日果酒祝福语简短独特
14 高考送考祝福语简短
15 古诗生日祝福语简短独特
16 父亲祝福语大全简短语
17 工厂祝福语简短的句子
18 38节贺卡简短祝福语