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?
-
1List is interface. Are you sure you checked the API?kdabir– kdabir2011年04月22日 18:25:30 +00:00Commented Apr 22, 2011 at 18:25
2 Answers 2
List
An interface that merely defines behavior of lists.ArrayList
AList
implementation, backed by an array. It is not a linked list.LinkedList
AList
implementation, backed by an implementation of a doubly-linked list.
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.
You can reverse any collection using Collections.reverse(..)
. LinkedList
(and any Deque
) has descendingIterator()