Vector elements() Method in Java
The java.util.vector.elements() method of Vector class in Java is used to get the enumeration of the values present in the Vector.
Syntax:
Enumeration enu = Vector.elements()
Parameters: The method does not take any parameters.
Return value: The method returns an enumeration of the values of the Vector.
Below programs are used to illustrate the working of the java.util.Vector.elements() method:
Program 1:
// Java code to illustrate the elements() method import java.util.*; public class Vector_Demo { public static void main(String[] args) { // Creating an empty Vector Vector<String> vec_tor = new Vector<String>(5); // Inserting elements into the table vec_tor.add("Geeks"); vec_tor.add("4"); vec_tor.add("Geeks"); vec_tor.add("Welcomes"); vec_tor.add("You"); // Displaying the Vector System.out.println("The Vector is: " + vec_tor); // Creating an empty enumeration to store Enumeration enu = vec_tor.elements(); System.out.println("The enumeration of values are:"); // Displaying the Enumeration while (enu.hasMoreElements()) { System.out.println(enu.nextElement()); } } } |
chevron_right
filter_none
Output:
The Vector is: [Geeks, 4, Geeks, Welcomes, You] The enumeration of values are: Geeks 4 Geeks Welcomes You
Program 2 :
import java.util.*; public class Vector_Demo { public static void main(String[] args) { // Creating an empty Vector Vector<Integer> vec_tor = new Vector<Integer>(5); // Inserting elements into the table vec_tor.add(10); vec_tor.add(15); vec_tor.add(20); vec_tor.add(25); vec_tor.add(30); // Displaying the Vector System.out.println("The Vector is: " + vec_tor); // Creating an empty enumeration to store Enumeration enu = vec_tor.elements(); System.out.println("The enumeration of values are:"); // Displaying the Enumeration while (enu.hasMoreElements()) { System.out.println(enu.nextElement()); } } } |
chevron_right
filter_none
Output:
The Vector is: [10, 15, 20, 25, 30] The enumeration of values are: 10 15 20 25 30
Recommended Posts:
- Vector add() Method in Java
- Vector contains() Method in Java
- Vector set() Method in Java
- Vector get() Method in Java
- Vector isEmpty() Method in Java
- Vector removeElementAt() Method in Java
- Vector indexOf() Method in Java
- Vector insertElementAt() Method in Java
- Vector hashCode() Method in Java
- Vector elementAt() Method in Java
- Vector equals() Method in Java
- Vector copyInto() Method in Java
- Vector remove() Method in Java
- Vector removeAll() Method in Java
- Vector firstElement() Method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




