Java Stream Practice: Finding Duplicate Characters

Day 5 – Java Stream Practice | Finding Duplicate Characters Today I worked on finding duplicate characters in a string using Java Streams. Problem: Given a string, identify characters that appear more than once. Approach: Removed spaces from the string Converted characters into a stream using chars() Used Collectors.groupingBy() along with counting() to calculate frequency Filtered characters with count greater than 2 This exercise helped me strengthen my understanding of: Stream transformations (chars(), mapToObj()) Frequency counting using grouping operations Writing clean and functional-style Java code Sample Input: I Love Java Output: Duplicate characters along with their frequency Consistently practicing Java Streams is improving my approach to data processing and problem solving. #Java #100DaysOfCode #JavaStreams #ProblemSolving #CodingJourney

  • ==1

Nice implementation using Java Streams ,since the problem is about finding duplicate characters, the condition should be count > 1 instead of count == 2. Using == 2 will miss characters that appear more than twice.

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories