Is there any way to access the successor or the predecessor of an element in Treeset of Java. Or is there any way of getting the iterator of a particular element so that we can use iterator.next() to get the next element.
Asked
Active
Viewed 2,766 times
2 Answers
10
use higher/lower
with the TreeSet set
is set.higher(e) like e.next() and set.lower(e) like e.prev()

Turo
- 4,724
- 2
- 14
- 27
1
You can get a particular TreeSet's iterator using the iterator() method, and you can retrieve a reverse iterator with the use of descendingIterator() method.

masm64
- 1,222
- 3
- 14
- 31