

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
IntStream distinct() method in Java
The distinct() method in the IntStream class in Java returns a stream consisting of the distinct elements of this stream.
The syntax is as follows
IntStream distinct()
Let’s say we have the following elements in the stream. Some of them are repeated
IntStream intStream = IntStream.of(10, 20, 30, 20, 10, 50, 80, 90, 100, 80);
To get the distinct elements, use the IntStream distinct() method.
The following is an example to implement IntStream distinct() method in Java
Example
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); } }
Output
Displaying the distinct elements: 10 20 30 50 80 90 100
- Related Questions & Answers
- IntStream asLongStream() method in Java
- IntStream peek() method in Java
- IntStream forEachOrdered() method in Java
- IntStream asDoubleStream() method in Java
- IntStream rangeClosed() method in Java
- IntStream sorted() method in Java
- IntStream findFirst() method in Java
- IntStream map() method in Java
- IntStream flatMap() method in Java
- IntStream iterator() method in Java
- IntStream limit() method in Java
- IntStream parallel() method in Java
- IntStream builder() method in Java
- IntStream empty() method in Java
- IntStream max() method in Java
Advertisements