public void remove(int index)
{
//Remove country at method parameter "index"
this.getCountries().remove(index);
}
public void removeAll()
{
//The list "clear" method removes all elements
this.getCountries().clear();
}
We can follow these patterns for basic sorting. For example our Lake objects understand "getSize", "getMaxDepth" and "getClarity" (used in the sorts in the examples).
public void sortBySize()
{
//Sort our list by size; largest first
this.lakes.sort((lake1, lake2) -> Integer.compare(lake2.getSize(), lake1.getSize()));
}
public void sortByDepth()
{
//Sort our list by depth. , deepest first
this.lakes.sort((lake1, lake2) -> Integer.compare(lake2.getMaxDepth(), lake1.getMaxDepth()));
}
public void sortByClarity()
{
//Sort our list by clarity, clearest first
this.lakes.sort((lake1, lake2) -> Integer.compare(lake2.getClarity(), lake1.getClarity()));
}
public static void println(Object o)
{
System.out.println(o.toString());
}