Alternatively, you can set listOfSources as SortedSet
SortedSet<String> listOfSources = new TreeSet<String>();
Then you can use the method last()without clicking on the TreeSet
listOfSources.remove(listOfSources.last());
I think this is the preferred approach since you believe your Set is in order.
source
share