Skip to content

Instantly share code, notes, and snippets.

@JosephineAkello
Created July 9, 2020 20:09
Show Gist options
  • Save JosephineAkello/9f884bead9ad226e8e7f15ed2177dbb8 to your computer and use it in GitHub Desktop.
Save JosephineAkello/9f884bead9ad226e8e7f15ed2177dbb8 to your computer and use it in GitHub Desktop.
Snippet to sort a hashmap
Sort By Key
List<Employees> employee = new ArrayList<>(map.keySet());
Collections.sort(employee);
Output -> [Anne, George, John, Mooh]
Sort by Value
List<Employee> employeeId = new ArrayList<>(map.values();
Collections.sort(employeeId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment