title: implementing compareTo() with generics and collection
body: <p>i m working with collections and i cant figure this out... I want to override compareTO() method based on the "data" variable in the Node class.. so that i can invoke collection.sort() to sort the arraylist..</p>
  
  <pre><code>public class Node&lt;E&gt; implements Comparable&lt;E&gt;{
  
      public E data;
      public Node&lt;E&gt; next;
  
      public Node(){
          data=null;
          next=null;
      }
  
      public Node(E data1){
          data=data1;
      }
  
      public E getData(){
          return data;        
      }
  
      public Node&lt;E&gt; getNext(){
          return next;        
      }
  
      @Override
      public int compareTo(E o) {
          // TODO Auto-generated method stub
          return 0;
      }
  }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>public class Test { 
      public static void main(String args[]){
          ArrayList&lt;Node&gt; arr= new ArrayList&lt;Node&gt;();
          Node n1=new Node(1);
          Node n2=new Node(3);
          Node n3=new Node(4);
          Node n4=new Node(3);
          Node n5=new Node(6);
          Node n6=new Node(2);
          arr.add(n1);
          arr.add(n2);
          arr.add(n3);
          arr.add(n4);
          arr.add(n5);
          arr.add(n6);
  
          Collections.sort(arr);  
      }
  }
  </code></pre>