java使⽤distinct_Java中的Stream.distinct()⽅法使⽤流类的distinct()⽅法返回由该流的不同元素组成的流。语法如下-Stream distinct()
⽰例
以下是在Stream类中实现distinct()⽅法的⽰例-import java.util.*;
public class Demo {
public static void main(String[] args) {
List list = Arrays.asList(10, 30, 40, 40, 50, 70, 90, 90, 100);
System.out.println("List = "+list);
System.out.println("Displaying only the distinct elements = ");
list.stream().distinct().forEach(System.out::println);
}
}
谢超武
输出结果List = [10, 30, 40, 40, 50, 70, 90, 90, 100]
Displaying only the distinct elements =
家里马桶堵了怎么办10
30
40
50
70
90
有机礼品100
⽰例
让我们看另⼀个例⼦-import java.util.*;
缴费基数什么意思public class Demo {
public static void main(String[] args) {
List list = Arrays.asList(10, 30, 40, 40, 50, 70, 90, 90, 100);
System.out.println("List = "+list);
System.out.println("Count of distinct elements = "+(list.stream().distinct().count()));
ppt怎么加音乐
System.out.println("Displaying only the distinct elements = ");
list.stream().distinct().forEach(System.out::println);
}
}
野兔的做法输出结果List = [10, 30, 40, 40, 50, 70, 90, 90, 100]
华为手机工程模式Count of distinct elements = 7
Displaying only the distinct elements = 10
30
40
50
上海高楼排名列表
70
90
100