Here is a Java Program to Get Sub List of Java ArrayList Example
Output of Above Java Program
Sub list contains :
2
3
2 is removed from sub list
After removing 2 from sub list, original ArrayList contains :
1
3
4
5
import java.util.ArrayList; import java.util.List; class ArrayListExample { public static void main(String[] args) { 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)); } }
Output of Above Java Program
Sub list contains :
2
3
2 is removed from sub list
After removing 2 from sub list, original ArrayList contains :
1
3
4
5