The following code snippets show you how to iterate and read java.util.Vector
elements using the java.util.Enumeration
.
package org.kodejava.util;
import java.util.Enumeration;
import java.util.Vector;
public class VectorEnumeration {
public static void main(String[] args) {
Vector<String> data = new Vector<>();
data.add("one");
data.add("two");
data.add("three");
StringBuilder sb = new StringBuilder("Data: ");
// Iterates vector object to read it elements
for (Enumeration<String> enumeration = data.elements();
enumeration.hasMoreElements(); ) {
sb.append(enumeration.nextElement()).append(",");
}
// Delete the last ","
sb.deleteCharAt(sb.length() - 1);
System.out.println(sb);
}
}
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024