You can use Collections.frequency:

numbers.stream().filter(i -> Collections.frequency(numbers, i) >1)
                .collect(Collectors.toSet()).forEach(System.out::println);
Answer from Bao Dinh on Stack Overflow
🌐
Medium
medium.com › @premchandu.in › finding-duplicates-using-java-streams-af97bc106cfc
Finding Duplicates using java streams | by Premchandu | Medium
March 3, 2024 - For each element in the stream, group them along with their frequency in a map, using Collectors.groupingBy() method.Then for each element in the collected map, if the frequency of any element is more than one, then this element is a duplicate ...
🌐
Stack Abuse
stackabuse.com › java-finding-duplicate-elements-in-a-stream
Java: Finding Duplicate Elements in a Stream
September 20, 2023 - Here, we try to add() each element to the Set. If it's not added, due to it being duplicate, we collect that value and print it out: ... Alternatively, you can also count the occurrences of duplicate elements and keep that information in a map that contains the duplicate elements as keys and their frequency as values. ... Map<Integer, Integer> map = list.stream() .collect(Collectors.toMap(Function.identity(), value -> 1, Integer::sum)); System.out.println(map);
🌐
Java2Blog
java2blog.com › home › core java › java 8 › java 8 – find duplicate elements in stream
Java 8 – Find duplicate elements in Stream - Java2Blog
October 16, 2021 - Add a map() method and pass Map.Entry::getKey, which returns a Stream of the elements that are duplicate and collect the result to a set using the Collectors.toSet() method. ... Employee{firstName=’john’, lastName=’doe’} Employee{fi...
🌐
TutorialsPoint
tutorialspoint.com › how-to-find-duplicate-elements-in-a-stream-in-java
How to find duplicate elements in a Stream in Java
July 19, 2023 - The Collections.frequency() method will count the occurrences of each element in the stream and then collects the elements with a count greater than one into a Set to remove duplicates. The resulting Set will contain only the duplicate elements from the stream. import java.util.stream.*; import ...
🌐
Mkyong
mkyong.com › home › java8 › java 8 – find duplicate elements in a stream
Java 8 – Find duplicate elements in a Stream | mkyong.com
March 15, 2020 - In Java 8 Stream, filter with Set.Add() is the fastest algorithm to find duplicate elements, because it loops only one time. Set<T> items = new HashSet<>(); return list.stream() .filter(n -> !items.add(n)) .collect(Collectors.toSet()); The ...
🌐
Medium
medium.com › @AlexanderObregon › javas-collectors-toset-method-explained-90c6d57894d5
Java's Collectors.toSet() Method Explained
September 12, 2024 - In situations where the input contains redundant elements, such as duplicate records or repeated values, the toSet() method makes sure that only the unique elements are retained in the final collection.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-stream-distinct-function
Java Stream distinct() Function to Remove Duplicates | DigitalOcean
Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
Benchresources
benchresources.net › home › java › java 8 – how to find duplicate in a stream or list ?
Java 8 - How to find duplicate in a Stream or List ? - BenchResources.Net
October 13, 2022 - For finding duplicates, use ... duplicates present in the Original List · Finally, store those elements into another new Set using collect(Collectors.toSet()) method · package net.bench.resources.java.stream; import java.util.ArrayList; import java.util.Collections; import ...
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java collections › java map › handle duplicate keys when producing map using java stream
Handle Duplicate Keys When Producing Map Using Java Stream | Baeldung
January 8, 2024 - However, this approach returns ... duplicated keys in this situation. Stream API has provided the toMap() collector method to collect a stream into a Map....
🌐
Stack Abuse
stackabuse.com › guide-to-java-8-collectors-toset
Guide to Java 8 Collectors: toSet()
May 19, 2023 - Set<String> booksGeorgeOrwell = ... Method and Functional Programming in Java 8: Definitive Guide to Predicates! As we discussed earlier, Sets don't allow for duplicates....
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › java stream – find, count and remove duplicates
Java Stream - Find, Count and Remove Duplicates
July 17, 2022 - ArrayList<Integer> numbersList = new ArrayList<>(Arrays.asList(1, 1, 2, 3, 3, 3, 4, 5, 6, 6, 6, 7, 8)); Set<Integer> setWithoutDuplicates = numbersList.stream() .collect(Collectors.toSet()); System.out.println(setWithoutDuplicates); ... Sometimes, ...
🌐
DEV Community
dev.to › realnamehidden1_61 › java-streamdistinct-495k
Java Stream.distinct() - DEV Community
November 17, 2024 - import java.util.List; import java.util.stream.Collectors; public class Main { public static void main(String[] args) { // List of names with duplicates List<String> names = List.of("Alice", "Bob", "Alice", "Charlie", "Bob", "David"); // Use Stream.distinct() to remove duplicates List<String> uniqueNames = names.stream() .distinct() .collect(Collectors.toList()); System.out.println(uniqueNames); // Output: [Alice, Bob, Charlie, David] } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-find-duplicate-elements-in-a-stream-in-java
How to find duplicate elements in a Stream in Java - GeeksforGeeks
July 12, 2025 - ... For each element in the stream, if it is not present in the set, add it. This can be done using Set.add() method. ... If the element is present in the Set already, then this Set.add() returns false.
🌐
Java67
java67.com › 2018 › 06 › how-to-remove-duplicates-from-stream-in-java8-distinct-example.html
How to remove duplicates from Collections or Stream in Java? Stream distinct() Example | Java67
*/ public class Hello { public static void main(String args[]) { List<Integer> withDupes = Arrays.asList(10, 10, 20, 20, 30, 30, 40, 50); System.out.println("List with duplicates: " + withDupes); List<Integer> withoutDupes = withDupes.stream() .distinct() .collect(Collectors.toList()); System.out.println("List without duplicates: " + withoutDupes); } } Output List with duplicates: [10, 10, 20, 20, 30, 30, 40, 50] List without duplicates: [10, 20, 30, 40, 50] You can see that the resulting List doesn't have a duplicate because we have collected it from the Stream after calling the distinct method, which removes the duplicate elements 10, 20, and 30. In other words, this is a new way to remove duplicate elements from a List in Java.
🌐
LinkedIn
linkedin.com › pulse › find-duplicate-strings-collection-using-java-streams-mohan-k
Find duplicate strings in a collection using Java streams
July 11, 2023 - 4. Collect the duplicate elements using `Collectors.toList()`. ... List<String> fruits = Arrays.asList("apple", "orange", "banana", "apple", "mango", "orange", "kiwi"); ... Mark contributions as unhelpful if you find them irrelevant or not valuable ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-stream-set-java
Convert Stream to Set in Java - GeeksforGeeks
July 18, 2026 - Java provides the following ways to convert a Stream into a Set. The Collectors.toSet() method is the most commonly used way to collect stream elements into a Set. It automatically removes duplicate elements.
🌐
YouTube
youtube.com › programming with chetan
Java 8 Stream API | How to find duplicate element from List using Java 8 | Lambda Expression in Java - YouTube
#Java8Features #StreamAPI #LambdaExpressionBy watching this tutorial you can find duplicate items from List using 3 different ways using Java 8 stream API fe...
Published: July 31, 2022
Views: 3K
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › java stream distinct(): collect unique values
Java Stream distinct(): Collect Unique Values
July 21, 2024 - ... Added in Java 8, the Stream.distinct() method returns a new Stream consisting of the distinct elements from the given Stream. The distinct() operation removes duplicate elements from a stream, ensuring that only unique elements are retained ...
🌐
Baeldung
baeldung.com › home › java › java list › finding all duplicates in a list in java
Finding All Duplicates in a List in Java | Baeldung
March 7, 2025 - Here, we’ll use a Set and convert the list to a stream. The stream is added to the Set, and the duplicate elements are filtered and collected into List: