JAVA EXAMPLE PROGRAMS

JAVA EXAMPLE PROGRAMS

Publish Your Article Here

Java Enumeration Sample Code

Description:

A class that implements Enumeration interface provides access to series of elements one at a time. You need to call nextElement method to get next element in the series. Also hasMoreElements() method gives you status about the availability of next element in the series.


Code:
package com.myjava.Enumeration;

import java.util.Enumeration;
import java.util.Vector;

public class MyEnumeration {
    public static void main(String a[]){
        Vector<String> lang = new Vector<String>();
        Enumeration<String> en = null;
        lang.add("JAVA");
        lang.add("JSP");
        lang.add("SERVLET");
        lang.add("EJB");
        lang.add("PHP");
        lang.add("PERL");
        en = lang.elements();
        while(en.hasMoreElements()){
            System.out.println(en.nextElement());
        }
    }
}

Example Output

JAVA
JSP
SERVLET
EJB
PHP
PERL

List Of Collection Classes Sample Programs:


List Of Util Classes Sample Programs:

Knowledge Centre
Purpose of garbage collection
The garbage collection process is to identify the objects which are no longer referenced or needed by a program so that their resources can be reclaimed and reused. These identified objects will be discarded.
Famous Quotations
Insanity: doing the same thing over and over again and expecting different results.
-- Albert Einstein

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2022 by Nataraja Gootooru. All Rights Reserved.