public class Abc implements Comparable<Abc>{ private Integer val; public Abc(Integer val){ setVal(val); } public Integer getVal(){ return this.val; } public void setVal(Integer val){ this.val = val; } @Override public int compareTo(Abc o){ return Abc.getVal().compareTo(o.getVal()); } }