// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SpecialSortInt {
    public static void main(String[] args) {
        List lst = new ArrayList();
        lst.add(new DataInt("CCC", 1));
        lst.add(new DataInt("BB", 2));
        lst.add(new DataInt("A", 3));
        lst.add(new DataInt("A", 4));
        lst.add(new DataInt("A", 2));
        for(int i = 0; i < lst.size(); i++) {
            System.out.println((DataInt)lst.get(i));
        }
        Collections.sort(lst, new CmpInt());
        for(int i = 0; i < lst.size(); i++) {
            System.out.println((DataInt)lst.get(i));
        }
    }
}

class DataInt {
    private String v1;
    private int v2;
    public DataInt(String v1, int v2) {
        this.v1 = v1;
        this.v2 = v2;
    }
    public String toString() {
        return (v1 + " " + v2);
    }
    public String getV1() {
        return v1;
    }
    public int getV2() {
        return v2;
    }
}

class CmpInt implements Comparator {
    public int compare(Object o1, Object o2) {
        int res = ((DataInt)o1).getV1().compareTo(((DataInt)o2).getV1()); 
        if(res == 0)
        {
            return ((DataInt)o1).getV2() - ((DataInt)o2).getV2(); 
        } else {
            return res;
        }
    }
    public boolean equals(Object obj)  {
        return false;
    }
}
