create and an enumeration of elements by instanting

Posted on 2006-05-09
Last Modified: 2010-03-31
is possible to instantiate java.util.Enumeration with some elements at once?
Question by:komlaaa
    LVL 86

    Expert Comment

    You can't instantiate any kind of Enumeration - it's an interface
    LVL 14

    Expert Comment

    you must subclass it in order to do instantiating.

    class YourEnumeration<E> implements java.util.Enumeration<E> {
          public boolean hasMoreElements() {
                // implement

          public E nextElement() {
                // implement
    LVL 92

    Accepted Solution

    you just instantiate a Collection (eg. Vector) with your elements and get the Enumeration from the Collection.
    LVL 30

    Expert Comment

    What do you intend to do after instantiating an enumeration? An enumeration is not independent but is dependent over something (like a collection, over which it enumerates).

    Author Comment

    Thanks object, I am sure you mean something like:
    Enumeration e = v.elements() ;
    >> What do you intend to do after instantiating an enumeration?
    Well i had a method that takes an Enumeration as argument, that is after instantiating the enumeration, i will pass it to
    the method i am not supposed to change.
    LVL 30

    Expert Comment

    >> that is after instantiating the enumeration,

    You will not instantiate it. You will get it from something (like a collection) and then pass it to the method.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    If you have upgraded to Java2 update 10 on a Microsoft Windows client, you may have discovered that your Java application does not work as it did before.  For example, the colors of your Java2D graphic may be all wrong for no apparent reason. Aft…
    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now