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?
List
ArrayList
List
implementation, backed by an array . It is not a linked list . LinkedList
List
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.