Document
Document
12. How to find all active employees with salary > 5000?
List<Employee> highEarners = employeeList.stream().filter(emp -> emp.isActiveEmp() &&
emp.getSalary() > 5000).toList();
15. How to get employee names from "Mumbai" sorted by salary descending?
List<String> mumbaiHighEarners = employeeList.stream().filter(emp ->
"Mumbai".equals(emp.getCity()))
.sorted(Comparator.comparingDouble(Employee::getSalary).reversed())
.map(Employee::getName)
.toList();
22. Find the first repeatating character in the string using stream api?
String str=”Java code threads”;
LinkedHashMap<Character,Long> input=str.toLowerCase().chars().mapToObj(c->(char)c).
collect(Collectors.groupingBy(x->x,LinkedhashMap::new,Collectors.counting()));
Character character=input.entrySet().stream().filter(x->x.getValue()>1).
map(x->x.getKey()).findFirst().get();
22. Find the first non-repeatating character in the string using stream api?
LinkedHashMap<Character,Long> output=str.toLowerCase().chars().mapToObj(c->(char)c).
Collect(Collectors.groupingBy(x->x,LinkedHashMap::new,Collectors.counting()));
Character character=input.entrySet().stream().filter(x->x.getValue()==1).
map(x->x.getKey()).findFirst().get();
32. Given a list of Strings, find the frequency of each word using Java Streams
List<String> words = Arrays.asList("apple", "cherry", "apple", "orange", "banana", "cherry");
Map<String,Long> input=Arrays.stream().collect(Collectors.groupingBy(Function.identity(),
Collectors.counting()));
39. Pair anagrams from a list of strings. one word consider only one anagram
String [] a1={"pat","tap","pan","map","team","tree","meat"};
List<String> list=Arrays.asList(a1);
Map<Object,List<String>> list1=list.stream().stream(Collectors.groupingBy(
x->toLowerCase().split(“ ”)).sorted(Collectors.toList()));
);
}
System.out.println(rev);