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 ...
๐ŸŒ
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 ...
๐ŸŒ
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 ...
๐ŸŒ
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...
๐ŸŒ
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.
๐ŸŒ
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....
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
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, ...
๐ŸŒ
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.
๐ŸŒ
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 โ€บ 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.
๐ŸŒ
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.
๐ŸŒ
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 ...
๐ŸŒ
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:
๐ŸŒ
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 ...
๐ŸŒ
Javahandson
javahandson.com โ€บ home โ€บ courses โ€บ java 8 โ€บ collecting data with streams โ€บ java 8 stream collect to list, set, and map: tolist, toset, and tomap
Java 8 Stream collect to List, Set, and Map: toList, toSet, and toMap - Java-HandsOn
2 weeks ago - You also get toUnmodifiableSet and toUnmodifiableMap. So you can lock down any of the three when needed. A Set is the right choice when you want unique items. It drops any repeats for you. Therefore, it is perfect for removing duplicates from a stream. The toSet collector works just like toList.