I am doing tests to do with Java8 an order of a List and I have problems to understand how to do it with java8.I have a list of people who are sorted when they come for their work but I want them to be ordered by age for each job descending That is to say that the list is already ordered for each type of work but now I want to use that list of people I have and for each type of job to sort it within the list I have of people. Always keeping the order of the List is to say that the order is given by the database as 1. Journeyman 2.Administrativo 3.contable I want that within the list follow that order but ordering by age since the age is disorderly (from least to most would have to order). I have managed to do it with the sort but I order the whole list would be sorted by each job within the list.
public class Personas {
String edad;
String trabajo;
public String getEdad() {
return edad;
}
public void setEdad(String edad) {
this.edad = edad;
}
public String getTrabajo() {
return trabajo;
}
public void setTrabajo(String trabajo) {
this.trabajo = trabajo;
}
} The list to order would be this;
Personas person = new Personas();
person.setEdad("70");
person.setTrabajo("camionero");
personas.add(person);
Personas person1 = new Personas();
person1.setEdad("40");
person1.setTrabajo("camionero");
personas.add(person1);
Personas person2 = new Personas();
person2.setEdad("70");
person2.setTrabajo("administrativo");
personas.add(person2);
Personas person3 = new Personas();
person3.setEdad("50");
person3.setTrabajo("administrativo");
personas.add(person3);
Personas person4 = new Personas();
person4.setEdad("70");
person4.setTrabajo("administrativo");
personas.add(person4);
Personas person5 = new Personas();
person5.setEdad("50");
person5.setTrabajo("administrativo");
personas.add(person5);
Thank you very much for your time. I will continue looking for how to do it in java8. (In java7 I would be doing a for the list indicating that if the get (i) .getWork is equal to get (i-1) .getWork I would check the dates of the two and otherwise the previous one would be modified to load the next one)