http://docs.oracle.com/javase/tutorial/collections/interfaces/order.html Sort vector or List import java.util.*; public class Test { class BedFormat implements Comparable { String chrom; int end; public int compareTo(BedFormat obj) { return (this.end > obj.end ) ? 1 : -1 ; } } public static void main() { List vp = new ArrayList (); vp.add(new BedFormat()); vp.add(new BedFormat()); .... vp.add(new BedFormat()); Collections.sort( vp ); // print // it will print according to end variable of object } } Example : Finding Median from a list class ExpReplica implements Comparable { double valReplica; public ExpReplica(double valReplica) { super(); this.valReplica = valReplica; } public int compareTo(ExpReplica obj) { ...