forked from sumeet-automation/selenium-java-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion28.java
More file actions
29 lines (22 loc) · 968 Bytes
/
Copy pathQuestion28.java
File metadata and controls
29 lines (22 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package string;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static java.lang.String.valueOf;
import static java.util.stream.Collectors.*;
//Write a program to the least occurring character from a given string.
public class Question28 {
public static void main(String[] args) {
String word = "aHHellooooee";
Map<Object, Set<String>> map = retrieveSetMap(word);
map.forEach((k,v)-> System.out.printf("Count: %s Values: %s\n",k,v));
System.out.println(map.values().stream());
}
private static Map<Object, Set<String>> retrieveSetMap(String word) {
return Stream.of(word.split(""))
.collect(groupingBy(each -> countFrequencyOfLetter(word, valueOf(each)), toSet()));
}
public static long countFrequencyOfLetter(String word, String letter) {
return Arrays.stream(word.split("")).filter(each -> each.equals(letter)).count();
}
}