Duplicate :
|
|
Duplicate :
|
|
Relates :
|
|
Relates :
|
A DESCRIPTION OF THE REQUEST : I would like LinkedHashSet to provide a descendingIterator() method like LinkedList does. Thank you for your consideration. JUSTIFICATION : Many times it would be useful to iterate over a LinkedHashSet in reverse. This would allow for the LinkedHashSet to support deque-like behavior while allowing for fast access to entries in the set. The current implementation already "maintains a doubly-linked list running through all of its entries." Thus support for reverse iteration, like LinkedList, should be relatively easy to provide. CUSTOMER SUBMITTED WORKAROUND : One workaround is LinkedHashSet<T> set = ... LinkedList<T> list = new LinkedList<>(set); Iterator<T> itr = list.descendingIterator(); while(itr.hasNext()) { T item = itr.next(); // do something } However, this makes a copy of the items in the set and is not practical for large sets. My current workaround is to build my own Collection, which is less desirable than a solution given directly by the SDK.
|