Is there an IndexSet and a Range class for Java?

2019-06-19 23:32发布

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?

3条回答
霸刀☆藐视天下
3楼-- · 2019-06-20 00:12

There is the Apache commons IntRange

查看更多
Animai°情兽
4楼-- · 2019-06-20 00:36

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.

查看更多
登录 后发表回答