Convert LinkedHashSet to List

  • Let's say List b is a LinkedList.
  • Let's say List a is also a LinkedList.

Question:

  • How to add this list in constant time?

Perhaps because LinkedList is supposedly a doubly linked list (otherwise it could not implement the Deque interface). And adding a doubly linked list is operation 0 (1).

The method addAlldoes not work in constant time.

Question:

  • How to convert LinkedHashSet to a list in constant time?

This is also possible because LinkedHashSet"it supports a doubly linked list passing through all its entries."

+3
source share
3 answers

, .. LinkedHashSet LinkedList , , .

, - , node, , , , , . , , - , , .

, , , , Java API , .

+5

. LinkedList node, node node LinkedList.

LinkedHashSet: , .

+5

, , , , .

, . Set<Whatever> whatever = SOME CONSTRUCTOR, List<Whatever> list = new LinkedList(whatever);, LinkedList Collections Set Collections.

+1

All Articles