Quick Index
Adding


public void add(Country newCountry)
{
	this.getCountries().add(newCountry);
}

public void add(String newName, int newAveTemperature,
					String newCapital, int newPopulationDensity)
{
	this.add(new Country(newName, newAveTemperature, newCapital, newPopulationDensity));
}

public void addAll(List<Country> newCountries)
{
	this.getCountries().addAll(newCountries);
}


Removing


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();
}


Sorting


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());
}


Runnable Examples



References