Im a Java noob but still trying to learn by reverse engineering codes. I read similar questions but still not able to figure out.
Ive defined a quadruplet array pair as :-
The content of pairList array is (1:2:3:6), (3:4:1:1), (1:2:3:3)
I want to ascending sort the pairList based on the fourth element, so the output should be (3:4:1:1), (1:2:3:3), (1:2:3:6)
public class Pair<L,C, R, S> {
private L l;
private R r;
private C c;
private S s;
public Pair(L l, R r, C c, S s){
this.l = l;
this.r = r;
this.c = c;
this.s = s;
}
public L getL(){ return l; }
public R getR(){ return r; }
public C getC(){ return c; }
public S getS(){ return s; }
public void setL(L l){ this.l = l; }
public void setR(R r){ this.r = r; }
public void setC(C c){ this.c = c; }
public void setS(S s){ this.s = s; }
}
List<Pair<String,Integer,Integer, Integer>> pairList = new ArrayList<Pair<String,Integer,Integer, Integer>>();
// Code for array population
Arrays.sort(pairList, new Comparator<Pair>() {
@Override
public int compare(Pair p1, Pair p2) {
return p1.getL().compareTo(p2.getL());
}
});
But Im getting this error :-
error: cannot find symbol
return p1.getL().compareTo(p2.getL());
^
symbol: method compareTo(Object)
location: class Object