Alexander Ljungberg
Alexander Ljungberg

Reputation: 6362

Is there an IndexSet and a Range class for Java?

In Objective-C Cocoa we have the NSIndexSet class which stores a series of unique indexes efficiently by keeping an array of ranges. E.g. the set 1, 2, ... 30, 57 would be stored as the ranges 1-30 and 57 rather than an array of 32 numbers. This facilitates huge selections to be stored in a simple and fast way. For example, if all rows between 1 and a million in a table selected, the index set collapses to just a tiny range and is fast to compare and intersect with.

Unfortunately this turns out to be rather hard to Google for. Is there an equivalent class for Java?

Upvotes: 6

Views: 1636

Answers (3)

Navi
Navi

Reputation: 8756

There is the Apache commons IntRange

Upvotes: 3

michaelok
michaelok

Reputation: 1134

Certainly not last and not least, there is a Range class in the Guava library. This article does a nice job of illustrating how you might use it.

Upvotes: 0

Related Questions