How to Initialize a Vector with a Specific Initial Capacity in Java? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In Java, Vector Class allows to creation of dynamic arrays that can grow or shrink as per the need. If we know the approximate size of elements, we will store this in the vector. Then we optimize memory usage, and we can initialize it with the specific initial capacity. In this article, we will learn how to initialize a Vector with a specific initial capacity in Java. Example Input-Output:Input: int initialCapacity = 10;Vector<String> string Vector = new Vector<>(initialCapacity); Output: A Vector named stringVector is created with the initial capacity of 10. Syntax:Vector<E> vector = new Vector<>(initialCapacity);E: The type of elements in Vector.initialCapacity: The initial capacity of the Vector. It represents the number of elements the Vector can initially store without the resizing.Program to Initialize a Vector with Initial Capacity in JavaBelow is the implementation to Initialize a Vector with Initial Capacity: Java // Java program to initialize a // Vector with a specific initial capacity import java.io.*; import java.util.Vector; // Driver Class public class GFG { // Main Function public static void main(String[] args) { // Initializing a Vector with // the specific initial capacity int Capacity = 10; Vector<String> stringVector = new Vector<>(Capacity); // Adding elements to Vector stringVector.add("Java"); stringVector.add("is"); stringVector.add("powerful."); // Displaying the elements of the Vector System.out.println("The Vector elements: " + stringVector); } } OutputThe Vector elements: [Java, is, powerful.] Explanation of the Program:In the above program, Initialization: The initial capacity is set to 10. A Vector named stringVector is created with this initial capacity.Adding Elements: Three string elements are added to stringVector.Displaying Elements: The elements of stringVector are printed to console. Comment More info M maha123 Follow Improve Article Tags : Java Java Programs Java-Collections Java-Vector Explore Java BasicsIntroduction to Java4 min readJava Programming Basics9 min readJava Methods7 min readAccess Modifiers in Java6 min readArrays in Java9 min readJava Strings8 min readRegular Expressions in Java7 min readOOP & InterfacesClasses and Objects in Java10 min readAccess Modifiers in Java6 min readJava Constructors10 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface11 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java6 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling8 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking15+ min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples8 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz | Level Up Your Java Skills1 min readTop 50 Java Project Ideas For Beginners and Advanced [Update 2025]15+ min read Like