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 Company Preparation M mguru4c05q Follow Improve Article Tags : Java Java Programs Java-Vector Java Examples Practice Tags : Java Similar Reads Interview PreparationInterview Preparation For Software DevelopersMust Coding Questions - Company-wise Must Do Coding Questions - Topic-wiseCompany-wise Practice ProblemsCompany PreparationCompetitive ProgrammingSoftware Design-PatternsCompany-wise Interview ExperienceExperienced - Interview ExperiencesInternship - Interview ExperiencesPractice @GeeksforgeeksProblem of the DayTopic-wise PracticeDifficulty Level - SchoolDifficulty Level - BasicDifficulty Level - EasyDifficulty Level - MediumDifficulty Level - HardLeaderboard !!Explore More...Data StructuresArraysLinked ListStackQueueBinary TreeBinary Search TreeHeapHashingGraphAdvance Data StructuresMatrixStringAll Data StructuresAlgorithmsAnalysis of AlgorithmsSearching AlgorithmsSorting AlgorithmsPattern SearchingGeometric AlgorithmsMathematical AlgorithmsRandomized AlgorithmsGreedy AlgorithmsDynamic ProgrammingDivide & ConquerBacktrackingBranch & BoundAll AlgorithmsProgramming LanguagesCC++JavaPythonC#Go LangSQLPHPScalaPerlKotlinWeb TechnologiesHTMLCSSJavaScriptBootstrapTailwind CSSAngularJSReactJSjQueryNodeJSPHPWeb DesignWeb BrowserFile FormatsComputer Science SubjectsOperating SystemsDBMSComputer NetworkComputer Organization & ArchitectureTOCCompiler DesignDigital Elec. & Logic DesignSoftware EngineeringEngineering MathematicsData Science & MLComplete Data Science CourseData Science TutorialMachine Learning TutorialDeep Learning TutorialNLP TutorialMachine Learning ProjectsData Analysis TutorialTutorial LibraryPython TutorialDjango TutorialPandas TutorialKivy TutorialTkinter TutorialOpenCV TutorialSelenium TutorialGATE CSGATE CS NotesGate CornerPrevious Year GATE PapersLast Minute Notes (LMNs)Important Topic For GATE CSGATE CoursePrevious Year Paper: CS exams Like