Get Sub List of Vector - Java Collection Framework

Java examples for Collection Framework:Vector

Description

Get Sub List of Vector

Demo Code

 
import java.util.Vector;
import java.util.List;
 
public class Main {
 
  public static void main(String[] args) {
 
    //create Vector object
    Vector v = new Vector();
   //from  w  w  w.  j  a v  a2  s. c o m
    //Add elements to Vector
    v.add("1");
    v.add("2");
    v.add("3");
    v.add("4");
    v.add("5");
   
    List lst = v.subList(1,3);
       
    //display elements of sub list.
    System.out.println("Sub list contains : ");
    for(int i=0; i< lst.size() ; i++)
      System.out.println(lst.get(i));
     
    //remove one element from sub list
    Object obj = lst.remove(0);
    System.out.println(obj + " is removed from sub list");
   
    //print original Vector
    System.out.println("After removing " + obj + " from sub list, original Vector contains : ");
    for(int i=0; i< v.size() ; i++)
      System.out.println(v.get(i));
   
  }
 
}

Result


Related Tutorials