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 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短