11:08 pm - Sunday July 15, 2018

ArrayList Example program for subList(int fromIndex, int toIndex)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
*@author :CandidJava.com
*@descriptions : This program explain the function and use of subList(int fromIndex, int toIndex). It is used to get an element in specified from and toindex of arrayList
*/

import java.io.*;
import java.util.*;
public class ArrayListSublist
{
public static void main(String arg[])throws Exception
{
ArrayList al=new ArrayList();//to create object for ArrayList class
al.add(50);//to add an element in arrayList
al.add(55);//to add an element in arrayList
al.add(60);//to add an element in arrayList
al.add(65);//to add an element in arrayList
al.add(70);//to add an element in arrayList
al.add(75);//to add an element in arrayList
al.add(80);//to add an element in arrayList
al.add(85);//to add an element in arrayList
al.add(90);//to add an element in arrayList
System.out.println(al);//to print all the elements in list
System.out.println("for specified index (2,7)");
System.out.println(al.subList(2,7));//to get an element in specified from and toindex of arrayList
}
}

Output:
[50, 55, 60, 65, 70, 75, 80, 85, 90]
for specified index (2,7)
[60, 65, 70, 75, 80]

 BACK

Filed in: Z-A All Java Codes

Comments are closed.