sortedset

How to get the last 25 elements of a SortedSet?

In Java I have a SortedSet that may have 100,000 elements. I would like to efficiently and elegantly get the last 25 elements. I'm a bit puzzled. To get the first 25 I'd iterate and stop after 25 elements. But I don't know how to iterate in reverse order. Any ideas? SortedSet<Integer> summaries = getSortedSet(); // what goes here :-( ...

Java SortedSet + Comparator, consistency with equals() question

I'd like to have a SortedSet of Collections (Sets themselves, in this case, but not necessarily in general), that sorts by Collection size. This seems to violate the proscription to have the Comparator be consistent with equals() - i.e., two collections may be unequal (by having different elements), but compare to the same value (becaus...

Add to SortedSet<T> and its complexity

MSDN states the following SortedSet(T).Add Method : If Count is less than the capacity of the internal array, this method is an O(1) operation. Could someone please explain "how so"? I mean when adding new value we need to find a correct place to add a value (comparing it with another values) and internal implementation looks like...

How to get the next element of a 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: onA...

How to add to SortedSet items from an Array?

I have a SortedSet defined this way: SortedSet<RatedMessage> messageCollection = new TreeSet<RatedMessage>(new Comp()); and I have an array of RatedMessage[] I had to use the array as the set misses the serialization feature, now I need to construct it back. Is there a quick way to add all the items from the array to the set again?...

Serialization issue with SortedSet, Arrays, an Serializable

I have this before the process: protected void onPostExecute(SortedSet<RatedMessage> result) { List<Object> list=Arrays.asList(result.toArray()); lancon.putExtra("results", list.toArray()); // as serializable } then in the other part I have Object o=this.getIntent().getSerializableExtra("results"); //at this point the o holds...

ConcurrentSkipListMap sorting: Can it be done by the value's compareTo?

In a game, I'm trying to keep a list of users and have it sorted by score, so that I could query the list at any given time and return (for example) the top ten users by score. This list should be thread-safe. I envision using the userName string as a key and the value would be a User object which implements Comparable and has properti...