How to split below list into list of lists based on name , salary and joining date without checking values. I want to do at runtime because I don't know values:
public class Employee {
private String name;
private long id;
BigDecimal sal;
private Date joinDate;
public Employee(String name, long id, BigDecimal sal,Date date) {
super();
this.name = name;
this.id = id;
this.sal = sal;
this.joinDate=date;
}
}
List<Employee> employeeList =new ArrayList<>();
SimpleDateFormat format =new SimpleDateFormat("MMddYYYY");
employeeList.add(new Employee("Mike",1000,BigDecimal.valueOf(200),format.parse("08122022")));
employeeList.add(new Employee("David",1001,BigDecimal.valueOf(100),format.parse("08112022")));
employeeList.add(new Employee("Mike",1002,BigDecimal.valueOf(200),format.parse("08122022")));
employeeList.add(new Employee("David",1003,BigDecimal.valueOf(100),format.parse("08112022")));
employeeList.add(new Employee("David",1003,BigDecimal.valueOf(200),format.parse("08112022")));
employeeList.add(new Employee("David",1003,BigDecimal.valueOf(200),format.parse("08122022")));
Output should be list of list employee objects , above list should return 3 list of employee objects
If I run below it will give me list contain Mike objects but at runtime I don’t know what data list contains so I can’t do really this , so basically @ runtime above list should compare elements And final list should be list of list employee objects
List result = employeeList.stream().filter(emp-> emp.getName().equals("Mike")) .collect(Collectors.toList())