Skip to main content

Posts

Showing posts from July, 2013

JAVA SORT COLLECTION List or Vector or arraylist or array

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) { ...

Java Thread tutorial

// Wait for the child threads to finish job before main thread ends public Class TestJoin{      public static void main(String args[]) {         Vector vecThread = new Vector ();         for(int curLen=1; curLen<=5;curLen= curLen+1) //         {             vecThread.add( new Thread(new Inner(curLen)) );         }         for(int i=0;i         {             vecThread.get(i).start();         }         try {             for(int i=0;i             {                 vecThread.get(i).join()...