Assume I have a user defined Java class called Foo such as:
public class Foo
{
private String aField;
@Override
public String toString()
{
Collections.sort(myPojoList, (a, b) -> a.getId() - b.getId()); //ASC
Collections.sort(myPojoList, (a, b) -> b.getId() - a.getId()); //DESC
//Alternatively use Integer.compare()
Collections.sort(myPojoList, (a, b) -> Integer.compare(a.getId(), b.getId())); //ASC
Collections.sort(myPojoList, (a, b) -> Integer.compare(b.getId(), a.getId())); //DESC
Collections.sort(myPojoList, (a, b) -> a.getName().compareTo(b.getName())); //ASC
Collections.sort(myPojoList, (a, b) -> b.getName().compareTo(a.getName())); //DESC
Collections.sort(myPojoList, (a, b) -> Boolean.compare(a.isMale(), b.isMale())); //ASC
Collections.sort(myPojoList, (a, b) -> Boolean.compare(b.isMale(), a.isMale())); //DESC
myPojoList= new ArrayList<>(new LinkedHashSet<>(myPojoList)); //Distinct