Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Help with recursive reversal of arraylist..

Name: not autistic enough 2011-05-06 17:25

why does this not work

   public static ArrayList<Integer> reverseList(ArrayList<Integer> tList)
{
   ArrayList<Integer> list = ListMethods.deepClone(tList);
   if (list.size() <= 1)
   {
      return list;

   }
   else
   {
      list.add(list.size(), list.get(0));
      list.remove(0);
      reverseList(list);
   }
   return list;
}

Exception in thread "main" java.lang.StackOverflowError
        at java.util.ArrayList.get(ArrayList.java:322)
        at java.util.AbstractList$Itr.next(AbstractList.java:345)
        at ListMethods.deepClone(ListMethods.java:29)
        at ListMethods.reverseList(ListMethods.java:38)
        at ListMethods.reverseList(ListMethods.java:48)

Name: Anonymous 2011-05-06 17:39

>>2
It's the error you get when you should have posted this shit at StackOverflow.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List