1. Stream API Questions
1. Stream API Questions
{
int id;
String name;
int age;
String gender;
String department;
int yearOfJoining;
double salary;
// constructor
// getters and setters
}
==============================================================
List<Employee> employeeList = new ArrayList<Employee>();
1. How many male and female employees are there in the organization ?
emps.stream()
.map(Employee::getDepartment)
.distinct()
.forEach(name -> System.out.println(name));
3. What is the average age of male and female employees ?
if(optional.isPresent()) {
Employee employee = optional.get();
System.out.println(employee);
}
5. Get the names of all employees who have joined after 2015 ?
emps.stream()
.filter(e -> e.yearOfJoining > 2015)
.map(e -> e.name)
.forEach(name -> System.out.println(name));
if(optional.isPresent()) {
System.out.println(optional.get());
}
if(optional.isPresent()) {
System.out.println(optional.get());
}
10. How many male and female employees are there in the Sales team ?
System.out.println(map);
13. What is the average salary and total salary of the whole organization ?
14. Separate the employees who are younger or equal to 25 years from those
employees who are older than 25 years ?