Java: Examples of the Java list/array `subList` method (list subset) | alvinalexander.com
If you print the results of each line you'll see the results on the right side of the comments. As shown:
- The first element in a list or array is at index 0
- The
toIndex
is exclusive, meaning it won't be included in the results - If you go outside the size of the initial list, you'll get an
IndexOutOfBoundsException
- The original list isn't modified; if you print
x
, you'll see that it still includes all of the original elements
If you ever need to extract a subset of a Java list or array into another list or array, I hope these Java subList examples are helpful.
Read full article from Java: Examples of the Java list/array `subList` method (list subset) | alvinalexander.com
No comments:
Post a Comment