The range class will handle the following situations:
- {M,N}: From the M-th element (inclusive) to the N-th element (exclusive).
- {M,}: From the M-th element (inclusive) to the end.
- {,N}: From the first element (inclusive) to the N-th element (exclusive).
The same as {0,N}.
- {N}: Just retrieve the N-th element. The same as {N,N+1}.
You can use the
Range
class like this:
Range fromAndTo = Range.build().from(1).to(5);
Range fromOnly = Range.build().from(3).build();
Range toOnly = Range.build().to(5).build();
Range only = Range.build().only(3);