IntStream distinct() 方法 (Java)
Java 中 IntStream 类中的 distinct() 方法返回包含此流的不同元素的流。
语法如下
IntStream distinct()
假设我们在流中具有以下元素。其中一些是重复的
IntStream intStream = IntStream.of(10, 20, 30, 20, 10, 50, 80, 90, 100, 80);
要获取不同的元素,请使用 IntStream distinct() 方法。
以下是在 Java 中实现 IntStream distinct() 方法的示例
示例
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("Displaying the distinct elements:");
intStream.distinct().forEach(System.out::println);
}
}产量
Displaying the distinct elements: 10 20 30 50 80 90 100
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP