VOOZH about

URL: https://www.geeksforgeeks.org/java/vector-sublist-method-in-java/

⇱ Vector subList() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Vector subList() Method in Java

Last Updated : 5 Oct, 2021

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:


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:


Output
The Vector is: [Welcome, To, Geek, For, Geeks]
The resultant values within the sub list: [To, Geek, For, Geeks]
Comment