Skip to content

Instantly share code, notes, and snippets.

@Alcar32
Created August 23, 2013 13:11
Show Gist options
  • Select an option

  • Save Alcar32/6319201 to your computer and use it in GitHub Desktop.

Select an option

Save Alcar32/6319201 to your computer and use it in GitHub Desktop.
Iterate reverse throu a list with list listiterator
// Substitute appropriate type.
ArrayList<...> a = new ArrayList<...>();
// Add elements to list.
// Generate an iterator. Start just after the last element.
ListIterator li = a.listIterator(a.size());
// Iterate in reverse.
while(li.hasPrevious()) {
System.out.println(li.previous());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment