Friday, 10 October 2014

Java : Collection Framework : ArrayList (How to get SubList)
























Click here to watch in Youtube : https://www.youtube.com/watch?v=0YwdG42FvJw

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");

    }

}

Output
arrayList : [Ram, Dave, Peter, Julia, Akram]

subList : [Ram, Dave, Peter]


To Download ArrayListDemoSublist Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/ArrayListDemoSublist.zip?attredirects=0&d=1

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • 1 comment:

    1. Well Explained example for getting sublist from list . there is good array list example for get sublist visit get sublist form arraylsit

      ReplyDelete