2

About the List, Linkedlist and Arraylist, which one is a one way list and which one is Doubly-linked list? And how could we reverse it?

Bozho
599k147 gold badges1.1k silver badges1.2k bronze badges
asked Apr 22, 2011 at 18:20
1
  • 1
    List is interface. Are you sure you checked the API? Commented Apr 22, 2011 at 18:25

2 Answers 2

8

If you want a single-linked list, you'll have to write it yourself.

I should point out that making a single linked list that implements java.util.List is not easy. It requires you to have a ListIterator<E>, and part of the ListIterator specification is that you can traverse in either direction with methods hasPrevious, previous, and previousIndex. So to keep it both efficient and true to the single linked list mantra would be very difficult.

Basil Bourque
345k128 gold badges943 silver badges1.3k bronze badges
answered Apr 22, 2011 at 18:22
4

You can reverse any collection using Collections.reverse(..). LinkedList (and any Deque) has descendingIterator()

answered Apr 22, 2011 at 18:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.