Example usage for java.util Enumeration nextElement

List of usage examples for java.util Enumeration nextElement

Introduction

In this page you can find the example usage for java.util Enumeration nextElement.

Prototype

E nextElement();

Source Link

Document

Returns the next element of this enumeration if this enumeration object has at least one more element to provide.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    Hashtable hashtable = new Hashtable();
    hashtable.put("apple", "red");
    hashtable.put("strawberry", "red");

    Enumeration e = hashtable.keys();
    while (e.hasMoreElements()) {
        Object k = e.nextElement();
        Object v = hashtable.get(k);
        System.out.println("key = " + k + "; value = " + v);
    }//w w w  .  j  a  v a 2s. c  om

}

From source file:MainClass.java

public static void main(String[] args) throws IOException {

    JarFile jf = new JarFile(args[0]);
    Enumeration e = jf.entries();
    while (e.hasMoreElements()) {
        JarEntry je = (JarEntry) e.nextElement();
        String name = je.getName();
        System.out.println(name);
    }//from   ww w  .j av a2 s .c o m
}

From source file:Main.java

public static void main(String args[]) throws IOException {

    JarFile jarFile = new JarFile("c:/abc/yourJarFileName.jar");
    Enumeration<JarEntry> e = jarFile.entries();
    while (e.hasMoreElements()) {
        process(e.nextElement());
    }/*from  w w w  .  j  a  va 2  s  . c  o m*/
    jarFile.close();
}

From source file:SaveVector1.java

public static void main(String args[]) throws Exception {
    Vector v = new Vector(Arrays.asList(args));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(v);/*from   ww w  . j a  va 2  s  .c om*/
    oos.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bais);
    Vector v2 = (Vector) ois.readObject();
    Enumeration e = v.elements();
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }
}

From source file:MainClass.java

public static void main(String[] args) {
    String data;// w  w  w.  j a  va2  s .  c om
    String msg;

    Hashtable h = new Hashtable(20);

    System.out.println(h.put("one", new Integer(1)));
    System.out.println(h.put("name", "A"));
    System.out.println(h.put("date", new Date()));
    System.out.println(h.put("one", new Integer(4)));

    Enumeration e = h.keys();
    while (e.hasMoreElements())
        System.out.println(e.nextElement());

    e = h.elements();
    while (e.hasMoreElements())
        System.out.println(e.nextElement());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    ProtectionDomain domain = String.class.getProtectionDomain();
    PermissionCollection pcoll = Policy.getPolicy().getPermissions(domain);
    Enumeration e = pcoll.elements();
    for (; e.hasMoreElements();) {
        Permission p = (Permission) e.nextElement();
    }//from   w w  w. j  a  v  a 2s. com
}

From source file:Main.java

public static void main(String args[]) throws IOException {

    JarFile jarFile = new JarFile(new File("c:/abc/yourJarFileName.jar"));
    Enumeration<JarEntry> e = jarFile.entries();
    while (e.hasMoreElements()) {
        process(e.nextElement());
    }/*  ww  w .  j ava 2s .c o  m*/
    jarFile.close();
}

From source file:PlanetDiameters.java

public static void main(String args[]) {
    String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" };
    float diameters[] = { 4800f, 12103.6f, 12756.3f, 6794f, 142984f, 120536f, 51118f, 49532f, 2274f };
    Hashtable hash = new Hashtable();
    for (int i = 0, n = names.length; i < n; i++) {
        hash.put(names[i], new Float(diameters[i]));
    }//from  w w  w  . j a va 2 s.c o  m
    Enumeration e = hash.keys();
    Object obj;
    while (e.hasMoreElements()) {
        obj = e.nextElement();
        System.out.println(obj + ": " + hash.get(obj));
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Vector v = new Vector(Arrays.asList("a", "b", "c"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(v);/*from   ww w  .  j  a v  a2 s .c  om*/
    oos.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ObjectInputStream ois = new ObjectInputStream(bais);
    Vector v2 = (Vector) ois.readObject();
    Enumeration e = v.elements();
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }
}

From source file:MainClass.java

public static void main(String[] s) {
    Hashtable table = new Hashtable();
    table.put("key1", "value1");
    table.put("key2", "value2");
    table.put("key3", "value3");

    Enumeration e = table.elements();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + table.get(key));
    }//w  w w .  ja v  a2s.  c o  m

    System.out.println(table.values());
}