Vector subList() Method in Java Last Updated : 05 Oct, 2021 Comments Improve Suggest changes Like Article Like Report The java.util.Vector.subList() is used to return a sublist of the existing Vector within a range mentioned in the parameter. The method takes in an upper limit and a lower limit and returns all the elements mentioned in the range. The lower limit is included if the element is present in the list and the upper limit is excluded. Basically, it takes the sublist greater than equal to the lower limit and strictly less than the upper element. Syntax: Vector.subList(int low_index, int up_index) Parameters: The method accepts 2 mandatory parameters: low_index: This is of the integer type and defines the lower limit or the index of the starting element from which the subList is evaluated. This element is included in the sublist.up_index: This is of the integer type and defines the upper limit or the index of the end element till which the subList is evaluated. This element is excluded from the sublist. Return Value: The method returns a sublist of the Vector type mentioned within the given range of the parameters. Example 1: Java // Java Program to illustrate subList() method // of Vector class // Importing required class import java.util.*; // Main class public class GFG { // Main driver method public static void main(String[] args) { // Creating an empty Vector by declaring // object of Vector class of Integer type Vector<Integer> vec_tor = new Vector<Integer>(); // Adding custom input elements // using add() method vec_tor.add(5); vec_tor.add(1); vec_tor.add(50); vec_tor.add(10); vec_tor.add(20); vec_tor.add(6); vec_tor.add(20); vec_tor.add(18); vec_tor.add(9); vec_tor.add(30); // Print and display all elements present in vector System.out.println("The Vector is: " + vec_tor); // Creating the sublist vector List<Integer> sub_list = new ArrayList<Integer>(); // Limiting the values till 5 // using subList() method via passing arguments sub_list = vec_tor.subList(2, 5); // Displaying the elements present inside list System.out.println("The resultant values " + "within the sub list: " + sub_list); } } Output: The Vector is: [5, 1, 50, 10, 20, 6, 20, 18, 9, 30] The resultant values within the sub list: [50, 10, 20] Example 2: Java // Java Program to illustrate subList() method // of Vector class // Importing required class import java.util.*; // Main class public class GFG { // Main driver method public static void main(String[] args) { // Creating an empty Vector by // creating string object of Vector class Vector<String> vec_tor = new Vector<String>(); // Adding custom input elements to above vector // object using add() method vec_tor.add("Welcome"); vec_tor.add("To"); vec_tor.add("Geek"); vec_tor.add("For"); vec_tor.add("Geeks"); // Display message only System.out.println("The Vector is: " + vec_tor); // Creating the sublist vector List<String> sub_list = new ArrayList<String>(); // Limiting the values till 5 // using subList() method sub_list = vec_tor.subList(1, 5); // Display elements of List object System.out.println("The resultant values " + "within the sub list: " + sub_list); } } OutputThe Vector is: [Welcome, To, Geek, For, Geeks] The resultant values within the sub list: [To, Geek, For, Geeks] Comment More infoAdvertise with us Next Article Vector subList() Method in Java K kundankumarjha Follow Improve Article Tags : Misc Java Java-Collections Java - util package Java-Functions Java-Vector +2 More Practice Tags : JavaJava-CollectionsMisc Similar Reads Vector lastIndexOf() Method in Java The Java.util.Vector.lastIndexOf(Object element) method is used to check and find the occurrence of a particular element in the vector. If the element is present in the vector then the lastIndexOf() method returns the index of last occurrence of the element otherwise it returns -1. This method is us 2 min read Vector listIterator() method in Java with Examples java.util.Vector.listIterator() This method returns a list iterator over the elements of a Vector object in proper sequence. It is bidirectional, so both forward and backward traversal is possible, using next() and previous() respectively. The iterator thus returned is fail-fast. This means that str 3 min read Vector removeAll() Method in Java The java.util.vector.removeAll(Collection col) method is used to remove all the elements from the vector, present in the collection specified. Syntax: Vector.removeAll(Collection col) Parameters: This method accepts a mandatory parameter col which is the collection whose elements are to be removed f 2 min read Vector removeAllElements() method in Java with Example The Java.util.Vector.removeAllElements() method is used to removes all components from this Vector and sets its size to zero. Syntax: Vector.removeAllElements() Parameters: The method does not take any parameter Return Value: The function does not returns any value. Below programs illustrate the Jav 2 min read Vector removeElement() method in Java with Example The java.util.Vector.removeElement() method is used to remove first occurrence of particular object. If object is not found then it returns false else it returns true. If a particular object is present inside vector and removeElement() method call on that vector element then this method reduces vect 3 min read Vector removeElementAt() Method in Java The java.util.vector.removeElementAt(int index) method is used to remove an element from a Vector from a specific position or index. In this process the size of the vector is automatically reduced by one and all other elements after the removed element are shifted downwards by one position. Syntax: 2 min read Vector removeIf() method in Java The removeIf() method of Vector removes all of those elements from Vector which satisfies the condition passed as a parameter to this method. This method returns true if some element are removed from the Vector. Java 8 has an important in-built functional interface which is Predicate. Predicate, or 3 min read Vector removeRange() method in Java with Example The removeRange() method of Vector in Java is used to remove all elements within the specified range from an Vector object. It shifts any succeeding elements to the left. This call shortens the Vector by (toIndex-fromIndex) elements where toIndex is the ending index and fromIndex is the starting ind 3 min read Vector retainAll() method in Java with Examples The retainAll method of class vector in java is an inbuilt function in Java which is used to retains only the elements in this Vector that are contained in the specified Collection. In other words, removes from this Vector all of its elements that are not contained in the specified Collection. Synta 3 min read Vector setElementAt() method in Java with Example The setElementAt() method of Java Vector is used to set the component at the specified index of this vector to be the specified object. The previous component at that position is discarded. The index must be a value greater than or equal to 0 and less than the current size of the vector. Syntax: pub 2 min read Like