- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
DoubleStream distinct() method in Java
The distinct() method of the DoubleStream class returns a stream consisting of the distinct elements of this stream.
The syntax is as follows
DoubleStream distinct()
To use the DoubleStream class in Java, import the following package
import java.util.stream.DoubleStream;
Create DoubleStream and add some elements to the stream
DoubleStream doubleStream = DoubleStream.of(39.8, 78.7, 64.7, 78.7, 47.8, 89.7, 78.7);
Now, to get the distinct elements, use the distinct() method
doubleStream.distinct()
The following is an example to implement DoubleStream distinct() method in Java. We have repeated elements in the stream
Example
import java.util.stream.DoubleStream; public class Demo { public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(39.8, 78.7, 64.7, 78.7, 47.8, 89.7, 78.7); System.out.println("Distinct elements..."); doubleStream.distinct().forEach(System.out::println); } }
Output
Distinct elements... 39.8 78.7 64.7 47.8 89.7
Advertisements