import java.util.ArrayList;
import java.util.List;
public class GetSubList {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList arrayList = new ArrayList();
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
arrayList.add("4");
arrayList.add("5");
List lst = arrayList.subList(1,3);
System.out.println("Sub list contains : ");
for(int i=0; i< lst.size() ; i++)
System.out.println(lst.get(i));
Object obj = lst.remove(0);
System.out.println(obj + " is removed from sub list");
System.out.println("After removing " + obj + " from sub list, original ArrayList contains : ");
for(int i=0; i< arrayList.size() ; i++)
System.out.println(arrayList.get(i));
}
}
Console:
Sub list contains :
2
3
2 is removed from sub list
After removing 2 from sub list, original ArrayList contains :
1
3
4
5