title: Reversing Singly Linked List?
body: <p>On different sites, i was looking for programme in java doing reversing the order
  of linked list(Singly Linked List and and doubly linked list) .I landed up on different sites like </p>
  
  <p>1)http://geek-o-pedia.blogspot.com/2007/07/how-would-you-reverse-singly-linked.html
  2)http://stackoverflow.com/questions/354875/reversing-a-linked-list-in-java-recursively</p>
  
  <p>PointA-As per my understanding these programmes(take link 1) are good when you are writing your linked list class as the
  programme is assuming we can access Node class which we can not(As its is private inner class in Linked List.)</p>
  
  <p>Point B-Apart from that this programme will permanently reverse the order of Source linked list. So when we iterate on this
  we will always get the elemts in reverse order.</p>
  
  <p>Please let me know if both the above points are correct</p>
  
  <p>So i tried to do it myself</p>
  
  <p>--Reversing the singly Linked List</p>
  
  <pre><code>LinkedList list1 = new LinkedList();
      list1.add(1);
      list1.add(2);
      list1.add(3);
      list1.add(4);
      list1.add(5);
  
  LinkedList reverseList1 = new LinkedList();
  
  int size= list1.size();
  
  // below loop will revrse the order of source linked list i.e list1
  
  for(int i =size-1;i&gt;=0;i--)
  {
  reverseList1.add(size-i-1, list1.get(i));
  }
  </code></pre>
  
  <p>Just wanted to ensure if above approach is correct as i could not find these approach on internet which i found very simple .Everywhere i could find the approach similar to link1 and link2</p>
  
  <p>posted at <a href="https://forums.oracle.com/forums/thread.jspa?threadID=2271413&amp;tstart=0" rel="nofollow">https://forums.oracle.com/forums/thread.jspa?threadID=2271413&amp;tstart=0</a> too but did not get proper answer.</p>