I need help to write a comparator :-
I want this output :-
Martin Joseph Male 4/2/1979 Green
Ramya Patil Female 5/4/2009 Red
Don kelly Male 5/6/1986 Yellow
Van Shinde female 3/4/1984 Green
But i am getting the following output :-
Output 1:
Van Shinde female 3/4/1984 Green
Don kelly Male 5/6/1986 Yellow
Ramya Patil Female 5/4/2009 Red
Martin Joseph Male 4/2/1979 Green
how do i sort on last name keeping the order of the list intact .. i mean i want to output female first sorting on last name and then male sorted on last name ... please help me guys ..
this is the comparator i am using after i use the gender comparator :-
public class LastNameComparator implements Comparator<Person> {
public int compare(Person name_one, Person name_two) {
// TODO Auto-generated method stub
if(name_one.getGender().equals(name_two.getGender())){
return name_one.getLast_name().compareTo(name_two.getLast_name());
}else{
return name_one.getLast_name().compareTo(name_two.getLast_name());
}
}
}