Skip to content

Latest commit

 

History

History
29 lines (23 loc) · 349 Bytes

README.md

File metadata and controls

29 lines (23 loc) · 349 Bytes

Comparing Objects

class needs to implement java.lang.Comparable

public class Student implements Comparable<Student>
{
    ...
}

useful for

  • sorting
  • TreeSet
  • TreeMap

Need to implement

@Override
public int compareTo(Student arg0) 
{
    if (arg0 == this)
        return 0;
    
    // logic goes here
    ...
}