Click ⭐if you like the project. Pull Requests are highly appreciated. Connect me @Priyanka for technical content.
-
List<Employee> aEmp = empList.stream() .filter(emp -> emp.getName().startsWith("A")) .collect(Collectors.toList());
-
Map<String, List<Employee>> deptMap = empList.stream() .collect(Collectors.groupingBy(emp -> emp.getDepartmentName()));
-
long empCount = empList.stream().count();
-
int maxAge = empList.stream().mapToInt(emp -> emp.getAge()).max().getAsInt();
-
List<String> deptNamesList = empList.stream() .map(emp -> emp.getDepartmentName()).collect(Collectors.toList());
-
Map<String, Long> deptCountMap = empList.stream().collect(Collectors.groupingBy(Employee::getDepartmentName, Collectors.counting()));
-
List<Employee> ageList = empList.stream().filter(emp -> emp.getAge() < 30).collect(Collectors.toList());
-
List<Employee> ageBetween26And30 = employees.stream().filter(emp -> emp.getAge() < 30 && emp.getAge() > 26).collect(Collectors.toList());
-
Map<String, Double> avgAgeMap = empList.stream().collect(Collectors.groupingBy(Employee::getGender, Collectors.averagingInt(Employee::getAge)));
Map.Entry<String, Long> deptMaxCount = empList.stream().collect(Collectors.groupingBy(
Employee::getDepartmentName, Collectors.counting()))
.entrySet().stream().max(Map.Entry.comparingByValue()).get();
List<Employee> employees = empList.stream().filter(emp -> emp.getAddress().equals("Delhi")).sorted(Comparator.comparing(Employee::getName)).collect(Collectors.toList());
Map<String, Double> deptAvgSalary = empList.stream().collect(Collectors.groupingBy(Employee::getDepartmentName, Collectors.averagingDouble(Employee::getSalary)));
Map<String, Optional<Employee>> highestSalForEachDedpt = employees.stream().collect(Collectors.groupingBy(Employee::getDepartNames, Collectors.minBy(Comparator.comparing(Employee::getSalary))));
List<Employee> emps = empList.stream().sorted(Comparator.comparing(Employee::getSalary)).collect(Collectors.toList());
Employee emp = empList.stream().sorted(Comparator.comparing(Employee::getSalary)).skip(1).findFirst().get();
Good luck with your interview 😊