Write a Java program to get the subList from the Vector collection


The code you provided is written in Java and demonstrates how to create a sublist from a Vector collection using the subList() method. In the code, a Vector named vec_list is created and populated with integer values.

The subList() method is then called on the vec_list object to create a sublist. The subList() method takes two arguments: the starting index (inclusive) and the ending index (exclusive) of the sublist. In this case, the sublist is created from index 3 to index 8.

The resulting sublist is stored in a List variable named sub_list. Finally, the original vector collection and the sublist are printed using System.out.println() statements.

Source Code

import java.util.*;
public class Sublist
{
	public static void main(String[] args)
	{
		Vector < Integer > vec_list = new Vector < Integer > ();
		vec_list.add(100);
		vec_list.add(20);
		vec_list.add(57);
		vec_list.add(40);
		vec_list.add(5);
		vec_list.add(60);
		vec_list.add(7);
		vec_list.add(66	);
		vec_list.add(35);
		vec_list.add(10);
 
		List < Integer > sub_list = vec_list.subList(3, 8);
 
		System.out.println("Vector Collection : " + vec_list);
		System.out.println("Sub List of Vector Collection : " + sub_list);
	}
}

Output

Vector Collection : [100, 20, 57, 40, 5, 60, 7, 66, 35, 10]
Sub List of Vector Collection : [40, 5, 60, 7, 66]

Example Programs