Guest User

Untitled

a guest
Apr 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. public Collection<Country> getMostPopulatedCountries() {
  2. int maxPop = 0;
  3. Set<Country> countries = new HashSet<Country>();
  4. for (Country country : getAllCountries()) {
  5. if (country.getPopulation() == maxPop) {
  6. countries.add(country);
  7. } else {
  8. if (country.getPopulation() > maxPop) {
  9. countries.clear();
  10. countries.add(country);
  11. }
  12. }
  13. }
  14.  
  15. return countries;
  16. }
Add Comment
Please, Sign In to add comment