Tag: collections

  • The different ways to sort Collections in Java

    Let’s say you have an Employee class with attributes like name , age , rating etc. You want to create a number of employees and sort them all by name. How to do this in Java? You make the Employee class implement Comparable interface which has a method compareTo(). The Employee class needs to implement…