Example usage for java.util Collections enumeration

List of usage examples for java.util Collections enumeration

Introduction

In this page you can find the example usage for java.util Collections enumeration.

Prototype

public static <T> Enumeration<T> enumeration(final Collection<T> c) 

Source Link

Document

Returns an enumeration over the specified collection.

Usage

From source file:Main.java

public static void main(String[] args) {
    Vector<String> v = new Vector<String>();

    v.add("A");/* w  w w  . j av  a  2 s .  c om*/
    v.add("B");
    v.add("D");
    v.add("E");
    v.add("F");

    Enumeration e = Collections.enumeration(v);
    while (e.hasMoreElements())
        System.out.println(e.nextElement());
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Vector v = new Vector();
    v.add("a");/*  w  ww  . ja v a 2  s.c  o m*/
    v.add("b");
    v.add("c");

    Collection col = v;
    Enumeration e = Collections.enumeration(col);

    for (; e.hasMoreElements();) {
        Object o = e.nextElement();
        System.out.println(o);
    }
}

From source file:Main.java

public static void main(String[] args) {
    HashSet<String> hashSet = new HashSet<String>();

    hashSet.add("A");
    hashSet.add("B");
    hashSet.add("D");
    hashSet.add("E");
    hashSet.add("F");

    Enumeration e = Collections.enumeration(hashSet);
    while (e.hasMoreElements())
        System.out.println(e.nextElement());
}

From source file:Main.java

public static void main(String[] args) {
    HashSet<String> hashSet = new HashSet<String>();

    hashSet.add("A");
    hashSet.add("B");
    hashSet.add("D");
    hashSet.add("E");
    hashSet.add("F");

    Enumeration e = Collections.enumeration(hashSet);
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }/*  w  w  w.  j  a v a  2s.c  om*/
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Vector<String> v = new Vector<String>();
    v.add("a");/*w  w w  . j  a  va2  s  .c o  m*/
    v.add("b");
    v.add("c");

    Collection<String> col = v;
    Enumeration<String> e = Collections.enumeration(col);

    for (; e.hasMoreElements();) {
        Object o = e.nextElement();
        System.out.println(o);
    }
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> arrayList = new ArrayList<String>();

    arrayList.add("A");
    arrayList.add("B");
    arrayList.add("D");
    arrayList.add("E");
    arrayList.add("F");

    Enumeration e = Collections.enumeration(arrayList);

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

From source file:Main.java

public static void main(String args[]) throws Exception {
    Vector<String> v = new Vector<String>();
    v.add("a");//from  ww w  .  java  2s  .  c  o m
    v.add("b");
    v.add("java2s.com");

    Collection<String> col = v;
    Enumeration<String> e = Collections.enumeration(col);

    for (; e.hasMoreElements();) {
        Object o = e.nextElement();
        System.out.println(o);
    }
}

From source file:Main.java

public static void main(String args[]) {
    // create array list object       
    List<String> arrlist = new ArrayList<String>();

    // populate the list
    arrlist.add("A");
    arrlist.add("B");
    arrlist.add("from java2s.com");

    // create Enumeration
    Enumeration<String> e = Collections.enumeration(arrlist);

    while (e.hasMoreElements()) {
        System.out.println("Value is: " + e.nextElement());
    }/*from ww  w  .j  a va  2  s.c  om*/
}

From source file:Utilities.java

public static void main(String[] args) {
    List list = Arrays.asList("one Two three Four five six one".split(" "));
    System.out.println(list);//from ww w .  ja  v a2s.c  o  m
    System.out.println("max: " + Collections.max(list));
    System.out.println("min: " + Collections.min(list));
    AlphabeticComparator comp = new AlphabeticComparator();
    System.out.println("max w/ comparator: " + Collections.max(list, comp));
    System.out.println("min w/ comparator: " + Collections.min(list, comp));
    List sublist = Arrays.asList("Four five six".split(" "));
    System.out.println("indexOfSubList: " + Collections.indexOfSubList(list, sublist));
    System.out.println("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist));
    Collections.replaceAll(list, "one", "Yo");
    System.out.println("replaceAll: " + list);
    Collections.reverse(list);
    System.out.println("reverse: " + list);
    Collections.rotate(list, 3);
    System.out.println("rotate: " + list);
    List source = Arrays.asList("in the matrix".split(" "));
    Collections.copy(list, source);
    System.out.println("copy: " + list);
    Collections.swap(list, 0, list.size() - 1);
    System.out.println("swap: " + list);
    Collections.fill(list, "pop");
    System.out.println("fill: " + list);
    List dups = Collections.nCopies(3, "snap");
    System.out.println("dups: " + dups);
    // Getting an old-style Enumeration:
    Enumeration e = Collections.enumeration(dups);
    Vector v = new Vector();
    while (e.hasMoreElements())
        v.addElement(e.nextElement());
    // Converting an old-style Vector
    // to a List via an Enumeration:
    ArrayList arrayList = Collections.list(v.elements());
    System.out.println("arrayList: " + arrayList);

}

From source file:com.adobe.aem.demomachine.Checksums.java

public static void main(String[] args) {

    String rootFolder = null;/*w  w  w .j  a  va  2s .  com*/

    // Command line options for this tool
    Options options = new Options();
    options.addOption("f", true, "Demo Machine root folder");
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("f")) {
            rootFolder = cmd.getOptionValue("f");
        }

    } catch (Exception e) {
        System.exit(-1);
    }

    Properties md5properties = new Properties();
    List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths);
    for (String[] path : listPaths) {
        if (path.length == 5) {
            logger.debug(path[1]);
            File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : ""));
            if (pathFolder.exists()) {
                String md5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]), false);
                logger.debug("MD5 is: " + md5);
                md5properties.setProperty("demo.path." + path[0], path[1]);
                md5properties.setProperty("demo.md5." + path[0], md5);
            } else {
                logger.error("Folder cannot be found");
            }
        }
    }

    File md5 = new File(rootFolder + File.separator + "conf" + File.separator + "checksums.properties");
    try {

        @SuppressWarnings("serial")
        Properties tmpProperties = new Properties() {
            @Override
            public synchronized Enumeration<Object> keys() {
                return Collections.enumeration(new TreeSet<Object>(super.keySet()));
            }
        };
        tmpProperties.putAll(md5properties);
        tmpProperties.store(new FileOutputStream(md5), null);
    } catch (Exception e) {
        logger.error(e.getMessage());
    }

    System.out.println("MD5 checkums generated");

}