If startindex
and endindex
are integer positions, then your ArrayList
implementation isn't actually that far off from the best that's feasible, though it'd be slightly more efficient to write
FluentIterable.from(table.cellSet()).skip(fromIndex).limit(toIndex).toList()
That implementation won't copy any more of the elements than it has to into the result list.
Generally speaking, there's not an efficient way to do this for an arbitrary SortedSet
, SortedMap
, or pretty much any of the sorted data structures that come with Java.