List to sublist
In this chapter you will learn:
Get the sub list from a list
List<E> subList(int fromIndex, int toIndex)
Returns a portion of list between the specified fromIndex
,
inclusive, and toIndex
, exclusive.
import java.util.ArrayList;
import java.util.List;
// j av a 2s . c o m
public class Main {
public static void main(String[] args) {
List list = new ArrayList();
list.add("1");
list.add("2");
list.add("3");
list.add("java2s.com");
System.out.println(list);
List subList = list.subList(1,3);
System.out.println(subList);
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Collections