Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
I am learning GoF Java Design Patterns and I want to see some real life examples of them. Can you guys point to some good usage of these Design Patterns.(preferably in Java's core libraries). Thank you
In Java 5 and above you have the foreach loop, which works magically on anything that implements Iterable: for (Object o : list) { doStuff(o); } However, Enumerable still does not implement Iterable, meaning that do iterate over an Enumeration you must do the following: for(; e.hasMoreElements() ;) { doStuff(e.getNextElement()); } Does anyone know if there is a reason why Enumeration ...
Why can't I do: Enumeration e = ... for (Object o : e) ...
what is the exact different of both.. is using enumeration more benefit than using iterator..? can anyone elaborate.. any reference article would be appeciated
If enums are used from jdk1.5 onwards , what was the use of java.util.Enumeration interface before jdk1.5 ? Can anybody help me explore this with an example please ?
Is it possible for me to convert a String to an equivalent value in an Enumeration, using Java. I can of course do this with a large if-else statement, but I would like to avoid this if possible. Given this documentation: http://download.oracle.com/javase/1.4.2/docs/api/java/util/Enumeration.html I am not too hopeful that this is possible without ifs or a case statement.
What's does Enumeration<?> mean? Is there any way to represent the general generic?
I still have a question about Enumerations. Here's a quick sketch of the situation. I have a class Backpack that has a Hashmap content with as keys a variable of type long, and as value an ArrayList with Items. I have to write an Enumeration that iterates over the content of a Backpack. But here's the catch: in a Backpack, there can also be another Backpack. And the Enumeration should also be ...
I have a class that implements the Enumeration<T> interface, but Java's foreach loop requires the Iterator<T> interface. Is there an Enumeration to Iterator Adapter in Java's standard library?
Basic question here, can I put String variables into a position in a string array along with more text? Here's what I'm trying to do public static final String CAT_BUD_TAB = "CAT_BUD_TAB"; public static final String inI = "INSERT INTO "; public static final String val = " VALUES "; public static final String[] catInsertArray = new String[13]; catInsertArray[0] = inI + CAT_BUD_TAB + val + "...
I have a JSP page that receives an ArrayList of event objects, each event object contains an ArrayList of dates. I am iterating through the event objects with the following: How can I iterate through the dateTimes ArrayList of each event object and print out each events date/times ?
 /*
  * Copyright 1994-2005 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Sun designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */
package java.util;

An object that implements the Enumeration interface generates a series of elements, one at a time. Successive calls to the nextElement method return successive elements of the series.

For example, to print all elements of a Vector<E> v:

   for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
       System.out.println(e.nextElement());

Methods are provided to enumerate through the elements of a vector, the keys of a hashtable, and the values in a hashtable. Enumerations are also used to specify the input streams to a SequenceInputStream.

NOTE: The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.

public interface Enumeration<E> {
    
Tests if this enumeration contains more elements.

Returns:
true if and only if this enumeration object contains at least one more element to provide; false otherwise.
    boolean hasMoreElements();

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

Returns:
the next element of this enumeration.
Throws:
NoSuchElementException if no more elements exist.
    E nextElement();
New to GrepCode? Check out our FAQ X