3:43 am - Monday June 25, 2018

Stack 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). */
import java.io.*;
import java.util.*;
public class StackSublist
{
public static void main(String arg[])throws Exception
{
Stack s=new Stack();//to create object for Stack class
s.add(100);//to add an element in Stack
s.add(200);//to add an element in Stack
s.add(300);//to add an element in Stack
s.add(400);//to add an element in Stack
s.add(500);//to add an element in Stack
s.add(600);//to add an element in Stack
s.add(700);//to add an element in Stack
s.add(800);//to add an element in Stack
s.add(900);//to add an element in Stack
System.out.println(s);//to print sl the elements in list
System.out.println("for given index (2,7)");
System.out.println(s.subList(2,7));//to get items specified from and to index of Stack
}
}


OUTPUT:
[100, 200, 300, 400, 500, 600, 700, 800, 900]
for specified index (2,7)
[300, 400, 500, 600, 700]

Filed in: Z-A All Java Codes

Comments are closed.