Skip to content

Latest commit

 

History

History

CompareTo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

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
    ...
}