title: How can i use Comparator to implement Bubble sort?
body: <p>How can i implement Bubble sort by using Comparator?</p>
  
  <p>Thank you.</p>
  
  <p>This is how my comparator looks:</p>
  
  <pre><code>class ColumnSorter implements Comparator {
    int colIndex;
  
    ColumnSorter(int colIndex) {
      this.colIndex = colIndex;
    }
  
    public int compare(Object a, Object b) {
    Vector v1 = (Vector) a;
    Vector v2 = (Vector) b;
    Object o1 = v1.get(colIndex);
    Object o2 = v2.get(colIndex);
  
    if (o1 instanceof String &amp;&amp; ((String) o1).length() == 0) {
      o1 = null;
    }
    if (o2 instanceof String &amp;&amp; ((String) o2).length() == 0) {
      o2 = null;
    }
  
    if (o1 == null &amp;&amp; o2 == null) {
      return 0;
    } else if (o1 == null) {
      return 1;
    } else if (o2 == null) {
      return -1;
    } else if (o1 instanceof Comparable) {
        return ((Comparable) o1).compareTo(o2);
    } else {
      return o1.toString().compareTo(o2.toString());
   }
  }
  }
  </code></pre>