Java Program to Iterate Vector using Enumeration Last Updated : 10 Feb, 2022 Comments Improve Suggest changes Like Article Like Report The Vector class implements a growable array of objects. It is available in java.util package. It implements the List interface. The Enumeration interface defines the methods by which you can traverse the elements in a collection of objects. Now in order to add elements Vector Syntax: public class Vector<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable java.util.Enumeration interface is one of the predefined interfaces, whose object is used for retrieving the data from collections framework variable( like Stack, Vector, HashTable, etc.) in a forward direction only and not in the backward direction. You can use the Java.util.Vector.addElement() method to append a specified element to the end of this vector by increasing the size of the vector by 1. The functionality of this method is similar to that of the add() method of the Vector class. Syntax: boolean addElement(Object element) Parameters: This function accepts a single parameter element of object type and refers to the element specified by this parameter is appended to the end of the vector. Return Value: This is a void type method and does not return any value. Example 1: Java // Java Program to Iterate Vector using Enumeration // Importing Enumeration class import java.util.Enumeration; // Importing vector class import java.util.Vector; public class GFG { // Main driver method public static void main(String a[]) { // Creating a new vector Vector<String> v = new Vector<String>(); // Adding elements to the end v.add("Welcome"); v.add("To"); v.add("Geeks for"); v.add("Geeks"); // Creating an object of enum Enumeration<String> en = v.elements(); while (en.hasMoreElements()) { // Print the elements using enum object // of the elements added in the vector System.out.println(en.nextElement()); } } } OutputWelcome To Geeks for Geeks Example 2: Java // Java Program to Iterate Vector using Enumeration // Importing Enumeration class import java.util.Enumeration; // Importing Vector class import java.util.Vector; public class GFG { // Main driver method public static void main(String a[]) { // Creating a vector object Vector<Integer> v = new Vector<Integer>(); // Adding elements to the end v.add(1); v.add(2); v.add(3); v.add(4); // Creating an enum object Enumeration<Integer> en = v.elements(); while (en.hasMoreElements()) { // Displaying elements of vector class // calling enum object System.out.println(en.nextElement()); } } } Output1 2 3 4 Comment More infoAdvertise with us Next Article Java Program to Iterate Vector using Enumeration sravankumar_171fa07058 Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Java-Vector +1 More Practice Tags : Java Similar Reads Get Enumeration over Java Vector In java, the vector is a typical dynamic array whose size can increase or decrease. While in array the size cannot be changed after declaration. We have to include file import java.util.Vector to use Vector and store values in it. Also, import java.util.Enumeration to use enumeration. Approach 1: Co 3 min read Java Program to Iterate Over Characters in String Given string str of length N, the task is to traverse the string and print all the characters of the given string using java. Illustration: Input : str = âGeeksforGeeksâ Output : G e e k s f o r G e e k sInput : str = "GfG" Output : G f G Methods: Using for loops(Naive approach)Using iterators (Opti 3 min read Iterate Over Vector Elements in Java Vector is like the dynamic array which can grow or shrink its size. Unlike array, we can store n-number of elements in it as there is no size limit. We can iterate over vector by the following ways: Simple for-loopEnhanced for-loopIteratorsEnumeration interface Method 1: Simple for-loop The idea is 4 min read Java Program to Read Elements using Enumeration in Hashtable The enumeration in java is one of the predefined interfaces, whose object is used for retrieving the data from collections framework variable(like Stack, Vector, HashTable, etc.) in a forward direction only and not in the backward direction. HashTable is a class The hash table class implements a Map 3 min read Program to Convert a Vector to List in Java Given a Vector, the task is to Convert Vector to List in Java Examples: Input: Vector: [1, 2, 3, 4, 5] Output: List: [1, 2, 3, 4, 5] Input : Vector = [a, b, c, d, e, f] Output : List = [a, b, c, d, e, f] Using Collections.list() method Syntax: List list = Collections.list(vec.elements()); Approach: 3 min read Java Program to Sort Vector Using Collections.sort() Method java.util.Collections.sort() method is present in java.util.Collections class. It is used to sort the elements present in the specified list of Collection in ascending order. Syntax: Public void sort(Vector object); Parameters: Instance of the vector as an argument Illustration: Collection.sort() me 2 min read Java Program to Search an Element in Vector A vector in Java is a dynamic array that can be resized as needed. It is synchronized, which means it is safe in multi-threaded programs. To find an element in a Vector we have to loop through its elements to find a match. In this article, we will learn how to search for a component in a Vector usin 3 min read Java Program to Shuffle Vector Elements Vectors basically fall in legacy classes but now it is fully compatible with collections. Java has many built-in functions to perform different operations on collections or other data types and one of them is shuffle. To shuffle Vector elements Collections.shuffle() method is used. It shuffle method 3 min read Searching Elements in Vector Using Index in Java Vector implements a dynamic array that means it can grow or shrink as required. Like an array, it contains components that can be accessed using an integer index. An element of a Vector can be searched using an index with different methods. Suppose if the element is not present in the Vector then th 4 min read Java Program to Copy Elements of ArrayList to Vector Vector implements List Interface, like ArrayList it also maintains insertion order but it is rarely used in the non-thread environment as it is synchronized, and due to which it gives a poor performance in adding, searching, deleting, and updating of its elements. To copy elements from one collectio 4 min read Like