ArrayListSubListExample.java
import java.util.ArrayList; import java.util.List; /* * Example of subList(int fromIndex, int toIndex) method */ public class ArrayListSubListExample { public static void main( String[] args ) { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("Ram"); arrayList.add("Dave"); arrayList.add("Peter"); arrayList.add("Julia"); arrayList.add("Akram"); System.out.println("arrayList : " + arrayList + "\n"); List<String> subList = arrayList.subList(0, 3); System.out.println("subList : " + subList + "\n"); } }
arrayList : [Ram, Dave, Peter, Julia, Akram] subList : [Ram, Dave, Peter]
https://sites.google.com/site/javaee4321/java-collections/ArrayListDemoSublist.zip?attredirects=0&d=1
See also:
Well Explained example for getting sublist from list . there is good array list example for get sublist visit get sublist form arraylsit
ReplyDelete