How to Implement a Custom Vector with Additional Functionality in Java? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In Java, the Vector class is a part of the Java Collections Framework providing the Dynamic Arrays that can be resized. However, there might be scenarios where you need a Custom Vector with additional functionality tailored to your specific requirements. PrerequisiteTo follow along, you should have a Basic understanding of Java programming particularly knowledge of classes, arrays, and Java Collections Framework. Example Java // Java Program to implement a custom // Vector with additional functionality import java.io.*; import java.util.Vector; // CustomVector class extending Vector class GFG<E> extends Vector<E> { // Method to calculate sum of elements public int calculateSum() { int sum = 0; // Iterating over elements for (E element : this) { // Checking if element is an Integer if (element instanceof Integer) { // Adding element to sum sum += (Integer) element; } } // Return sum of elements return sum; } } // Driver Class public class Main { // Main Function public static void main(String[] args) { // Creating an instance of the CustomVector GFG<Integer> customVector = new GFG<>(); // Adding elements to custom vector customVector.add(10); customVector.add(20); customVector.add(30); // Calculating the sum using custom method int sum = customVector.calculateSum(); // Displaying the result System.out.println("Sum of elements: " + sum); } } Output: Sum of elements: 60Explaination of the above Program:Method calculateSum() calculates the sum of elements in the vector.The calculateSum() method iterates through the elements of the vector and checks if each element is an instance of Integer. If it is, it adds it to the sum.In the main method, an instance of GFG with a type of Integer is created.Three integers are added to this GFG instance using the add() method.The calculateSum() method is then called to calculate the sum of the integers in the vector.Finally, the sum is printed to the console. Comment More infoAdvertise with us Next Article Copy Elements of One Java Vector to Another Vector in Java M mguru4c05q Follow Improve Article Tags : Java Java Programs Java-Vector Java Examples Practice Tags : Java Similar Reads How to Initialize a Vector with a Specific Initial Capacity in Java? 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 lear 2 min read Convert ArrayList to Vector in Java There are several ways to convert ArrayList to Vector. We can use a vector constructor for converting ArrayList to vector. We can read ArrayList elements one by one and add them in vector. Approach 1: (Using Vector Constructor) Create an ArrayList.Add elements in ArrayList.Create a vector and pass t 3 min read Copy Elements of One Java Vector to Another Vector in Java Vector is similar to arrays but is growable also, or we can say no fixed size is required. Previously vector was a part of legacy classes but now it is part of Collections. It also implements a List interface, so we can use any method of list interface on vectors also. Syntax : Vector<Integer> 3 min read Implementing Sorted Vector in Java Vector is a class that implements the List interface. It is a type of dynamic array that means the size of a vector can be grown or shrink during the execution of the program. The initial size of the vector is 10 and if we insert more than 10 elements then the size of the vector is increased by 100% 3 min read How to Replace an Element at a Specific Index of the Vector in Java? The Vector class implements a growable array of objects. Vectors basically fall in legacy classes but now it is fully compatible with collections. It is found in the java.util package and implements the List interface, so we can use all the methods of List interface here. Examples Input : Vector= [" 2 min read How to Get First and Last Element From the Vector in Java? The first element in the Vector can be obtained using the firstElement() method of vector class that is represent util package. The last element in the Vector can be obtained using the lastElement() method of vector class that is also represent util package. Neither of these methods requires any par 2 min read Like