Teachnique
      CourseRoadmaps
      Login

      OverviewHistoryFeaturesJava 8 - New Featuresvs C++Virtual Machine(JVM)JDK vs JRE vs JVMHello World ProgramEnvironment SetupBasic SyntaxVariable TypesData TypesType CastingUnicode SystemBasic OperatorsCommentsStreamsNew Date-Time API

      Loop ControlDecision Makingif-else Statementswitch statementfor loopfor each Loopwhile Loopdo...while Loopbreak Statementcontinue Statement

      OOPs (Object-Oriented Programming) ConceptsObject and ClassesClass AttributesClass MethodsMethodsVariable ScopesConstructorsAccess ModifiersInheritanceAggregationPolymorphismOverridingMethod OverloadingDynamic BindingStatic BindingInstance Initializer BlockAbstractionEncapsulationInterfacesPackagesInner classesStatic ClassesAnonymous ClassesSingleton ClassWrapper ClassesEnum Class

      Number ClassBoolean classCharacter ClassArraysMath Class

      File ClassCreating FilesWrite To FilesReading FileDelete FilesDirectory OperationsFiles and I/O

      ExceptionsTry Catch BlockTry with ResourcesMultiple Catch BlocksNested Try BlockFinally BlockThrows and Throw | Throw an ExceptionException PropagationBuilt-in ExceptionsCustom Exception

      MultithreadingThread Life CycleCreating a ThreadStarting a ThreadJoining ThreadsNaming a Thread with ExamplesScheduling Threads with ExamplesThread PoolsMain ThreadThread PriorityDaemon ThreadThreadGroup ClassJVM Shutdown Hook

      Thread SynchronizationBlock SynchronizationStatic SynchronizationInter Thread CommunicationThread DeadlockInterrupting ThreadThread ControlReentrant Monitor

      NetworkingSocket ProgrammingURL ProcessingURL ClassURLConnection ClassHttpURLConnection ClassSocket Class with ExamplesGenerics

      Collections FrameworkCollection Interface

      List InterfaceArrayList Class

      Queue InterfaceArrayDeque Class

      Map InterfaceSortedMap Interface

      Set InterfaceSortedSet Interface

      Data Structures Enumeration Interface BitSet Class

      How to Use Iterator?How to Use Comparator?How to Use Comparable?

      RecursionRegular ExpressionsSerializationString ClassJava Arrays - Class

      Feedback

      Submit request if you have any questions.

      Course
      Enumeration Interface

      Java Tutorial

      This Java tutorial is tailored for newcomers, offering a journey from basic principles to complex Java programming techniques. Completing this tutorial equips you with a solid understanding of Java, preparing you for advanced learning. You'll emerge ready to tackle the challenges of becoming a top-tier software engineer, with the skills to innovate and excel in the vast world of software development.

       Enumeration Interface

      
      The Enumeration interface defines the methods by which you can enumerate (obtain one at a time) the elements in a collection of objects.
      This legacy interface has been superceded by Iterator. Although not deprecated, Enumeration is considered obsolete for new code. However, it is used by several methods defined by the legacy classes such as Vector and Properties, is used by several other API classes, and is currently in widespread use in application code.

      Enumeration Interface Methods

      The methods declared by Enumeration are summarized in the following table
      Sr.No.
      Method & Description
      1
      boolean hasMoreElements( )
      When implemented, it must return true while there are still more elements to extract, and false when all the elements have been enumerated.
      2
      Object nextElement( )
      This returns the next object in the enumeration as a generic Object reference.

      Example 1: Enumeration for Vector

      Following is an example showing usage of Enumeration for a Vector.
      import java.util.Vector;
      import java.util.Enumeration;
      
      public class EnumerationTester {
      
      public static void main(String args[]) {
      Enumeration<String> days;
      Vector<String> dayNames = new Vector<>();
      dayNames.add("Sunday");
      dayNames.add("Monday");
      dayNames.add("Tuesday");
      dayNames.add("Wednesday");
      dayNames.add("Thursday");
      dayNames.add("Friday");
      dayNames.add("Saturday");
      days = dayNames.elements();
      while (days.hasMoreElements()) {
      System.out.println(days.nextElement());
      }
      }
      }

      Output

      Sunday
      Monday
      Tuesday
      Wednesday
      Thursday
      Friday
      Saturday

      Example 2: Enumeration for properties

      Following is an example showing usage of Enumeration for Properties to print the values.
      import java.util.Vector;
      import java.util.Enumeration;
      import java.util.Properties;
      
      public class EnumerationTester {
      
      public static void main(String args[]) {
      Enumeration<Object> days;
      Properties dayNames = new Properties();
      dayNames.put(1, "Sunday");
      dayNames.put(2,"Monday");
      dayNames.put(3,"Tuesday");
      dayNames.put(4,"Wednesday");
      dayNames.put(5,"Thursday");
      dayNames.put(6,"Friday");
      dayNames.put(7,"Saturday");
      days = dayNames.elements();
      while (days.hasMoreElements()) {
      System.out.println(days.nextElement());
      }
      }
      }

      Output

      Sunday
      Monday
      Tuesday
      Wednesday
      Thursday
      Friday
      Saturday