You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Q7 Given a String, find the first non-repeated character in it using Stream functions?
importjava.util.*;
importjava.util.stream.*;
importjava.util.function.Function;
publicclassMyClass {
publicstaticvoidmain(Stringargs[]) {
Stringinput = "Java Hungry Blog Alive is Awesome";
Characterresult = input.chars() // Stream of String
.mapToObj(s -> Character.toLowerCase(Character.valueOf((char) s))) // First convert to Character object and then to lowercase
.collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting())) //Store the chars in map with count
.entrySet()
.stream()
.filter(entry -> entry.getValue() == 1L)
.map(entry -> entry.getKey())
.findFirst()
.get();
System.out.println(result);
}
}
Q8 Given a String, find the first repeated character in it using Stream functions?
importjava.util.*;
importjava.util.stream.*;
importjava.util.function.Function;
publicclassJavaHungry {
publicstaticvoidmain(Stringargs[]) {
Stringinput = "Java Hungry Blog Alive is Awesome";
Characterresult = input.chars() // Stream of String
.mapToObj(s -> Character.toLowerCase(Character.valueOf((char) s))) // First convert to Character object and then to lowercase
.collect(Collectors.groupingBy(Function.identity(), LinkedHashMap::new, Collectors.counting())) //Store the chars in map with count
.entrySet()
.stream()
.filter(entry -> entry.getValue() > 1L)
.map(entry -> entry.getKey())
.findFirst()
.get();
System.out.println(result);
}
Q9 Given a list of integers, sort all the values present in it using Stream functions?