Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the next element of a SortedSet?

Tags:

java

sortedset

I have a SortedSet holding my ordered data.

I use the .first() method to return the first record, and pass it to another window.
When the other window finishes I get an event called, and I want to pass the next from the SortedSet to the window, so how to move to the next element?

launchWindow(this.set.first());

Then I have this:

onActivityResult(...) {
 if (this.set.hasNext()) launchWindow(this.set.next());//hasNext/next doesn't exists in the current context for SortedSet
}

What options I have?

like image 790
Pentium10 Avatar asked May 27 '10 20:05

Pentium10


People also ask

How do you find the last element in a sorted set?

The last() method of SortedSet interface in Java is used to return the last i.e., the highest element currently in this set. Where, E is the type of element maintained by this Set. Parameters: This function does not accepts any parameter. Return Value: It returns the last or the highest element currently in the set.

Is SortedSet ordered?

A set is used to provide a particular ordering on its element. The elements are ordered either by using a natural ordering or by using a Comparator. All the elements which are inserted into a sorted set must implement the Comparable interface. The set's iterator will traverse the set in an ascending order.

When should I use SortedSet?

A SortedSet contains only unique elements and is used to store data in a collection that needs to be in sorted order. By default, the elements of a SortedSet are in ascending order. The SortedSet<T> class implements the following interfaces: IReadOnlyCollection.

How do I add elements to a sorted set?

The add() method of SortedSet in Java is used to add a specific element into a Set collection. The function adds the element only if the specified element is not already present in the set else the function returns False if the element is already present in the Set.


1 Answers

Instead of the Set you should pass the Iterator, then next consumer would just call next()

like image 135
Eugene Kuleshov Avatar answered Nov 14 '22 22:11

Eugene Kuleshov