Get sub list from vector in java

The subList() method is used to get sub list from vector in java.

Syntax:

Vector.subList(int startIndex, int endIndex)

Example:

package com.w3spoint;
 
import java.util.List;
import java.util.Vector;
 
public class Test {
  public static void main(String args[]){
	Vector<String> vector = new Vector<String>();
        //adding elements to the end
	vector.add("Jai");
	vector.add("Mahesh");
	vector.add("Hemant");
	vector.add("Vishal");
	vector.add("Vivek");
	vector.add("Naren");
	System.out.println("Actual vector:"+vector);
	List<String> list = vector.subList(2, 5);
        System.out.println("Sub List: "+list);
  }
}

Output

Actual vector:[Jai, Mahesh, Hemant, Vishal, Vivek, Naren]
Sub List: [Hemant, Vishal, Vivek]
Please Share