diff --git a/core-java-modules/core-java-string-algorithms-3/pom.xml b/core-java-modules/core-java-string-algorithms-3/pom.xml
index 74a9486ec0..7d4adeba92 100644
--- a/core-java-modules/core-java-string-algorithms-3/pom.xml
+++ b/core-java-modules/core-java-string-algorithms-3/pom.xml
@@ -39,8 +39,8 @@
maven-compiler-plugin
${maven-compiler-plugin.version}
- ${java.version}
- ${java.version}
+ ${maven.compiler.source}
+ ${maven.compiler.target}
-parameters
diff --git a/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/charfreq/CharacterWithHighestFrequency.java b/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/charfreq/CharacterWithHighestFrequency.java
new file mode 100644
index 0000000000..938ad1edf3
--- /dev/null
+++ b/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/charfreq/CharacterWithHighestFrequency.java
@@ -0,0 +1,58 @@
+package com.baeldung.charfreq;
+
+import static java.util.Map.Entry.comparingByValue;
+import static java.util.stream.Collectors.counting;
+import static java.util.stream.Collectors.groupingBy;
+import static java.util.stream.Collectors.toSet;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+public class CharacterWithHighestFrequency {
+ public static Character byStream(String input) {
+ return input.chars()
+ .mapToObj(x -> (char) x)
+ .collect(groupingBy(x -> x, counting()))
+ .entrySet()
+ .stream()
+ .max(comparingByValue())
+ .get()
+ .getKey();
+ }
+
+ public static Set byMap(String input) {
+ Map map = new HashMap<>();
+ for (char c : input.toCharArray()) {
+ map.compute(c, (character, count) -> count == null ? 1 : ++count);
+ }
+ int maxCount = map.values()
+ .stream()
+ .mapToInt(Integer::intValue)
+ .max()
+ .getAsInt();
+
+ return map.keySet()
+ .stream()
+ .filter(c -> map.get(c) == maxCount)
+ .collect(toSet());
+ }
+
+ public static Set byBucket(String input) {
+ int[] buckets = new int[128];
+
+ int maxCount = 0;
+ for (char c : input.toCharArray()) {
+ buckets[c]++;
+ maxCount = Math.max(buckets[c], maxCount);
+ }
+
+ int finalMaxCount = maxCount;
+ return IntStream.range(0, 128)
+ .filter(c -> buckets[c] == finalMaxCount)
+ .mapToObj(i -> (char) i)
+ .collect(Collectors.toSet());
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/charfreq/CharacterWithHighestFrequencyUnitTest.java b/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/charfreq/CharacterWithHighestFrequencyUnitTest.java
new file mode 100644
index 0000000000..978752f3d4
--- /dev/null
+++ b/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/charfreq/CharacterWithHighestFrequencyUnitTest.java
@@ -0,0 +1,43 @@
+package com.baeldung.charfreq;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.junit.jupiter.api.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+class CharacterWithHighestFrequencyUnitTest {
+ private static final String INPUT1 = "aaaaaaaaaa(10) bbbbbbb ccccc dddd eee ff";
+ private static final Set EXPECTED1 = Collections.singleton('a');
+
+ private static final String INPUT2 = "YYYYYYY(7) bbbbb -------(7) dddd eee kkkkkkk(7) ff";
+ private static final Set EXPECTED2 = ImmutableSet.of('Y', '-', 'k');
+
+ @Test
+ void whenGettingSingleCharWithHighestFrequencyByStream_shouldSuccess() {
+ char result1 = CharacterWithHighestFrequency.byStream(INPUT1);
+ assertEquals('a', result1);
+ }
+
+ @Test
+ void whenGettingCharWithHighestFrequencyByMap_shouldSuccess() {
+ Set result1 = CharacterWithHighestFrequency.byMap(INPUT1);
+ assertEquals(EXPECTED1, result1);
+
+ Set result2 = CharacterWithHighestFrequency.byMap(INPUT2);
+ assertEquals(EXPECTED2, result2);
+
+ }
+
+ @Test
+ void whenGettingCharWithHighestFrequencyByBucket_shouldSuccess() {
+ Set result1 = CharacterWithHighestFrequency.byBucket(INPUT1);
+ assertEquals(EXPECTED1, result1);
+
+ Set result2 = CharacterWithHighestFrequency.byBucket(INPUT2);
+ assertEquals(EXPECTED2, result2);
+ }
+}
\ No newline at end of file