Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Vector toArray() Method in Java with Examples
Next article icon

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);
    }
}
 
 
Output
The Vector is: [Welcome, To, Geek, For, Geeks] The resultant values within the sub list: [To, Geek, For, Geeks]


Next Article
Vector toArray() Method in Java with Examples

K

kundankumarjha
Improve
Article Tags :
  • Java
  • Java - util package
  • Java-Collections
  • Java-Functions
  • Java-Vector
Practice Tags :
  • Java
  • Java-Collections

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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences