Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How convert Iterator into Enumeration

Reply
Thread Tools

How convert Iterator into Enumeration

 
 
markspace
Guest
Posts: n/a
 
      11-28-2012
On 11/28/2012 10:28 AM, Eric Sosman wrote:

> Aha! Thanks to Jim Janney, I've just learned about the
> Collections#enumeration(Collection) method. It's perhaps a
> smidgen less general than enumeration(Iterator) would be, but
> only a smidgen.
>
> (And I still don't see an iterator(Enumeration) method
> anywhere. Maybe Santa will bring one ...)



Yes, that was a useful post. I also note some other interesting methods:

static <T> Enumeration<T> emptyEnumeration()
Returns an enumeration that has no elements.

static <T> Iterator<T> emptyIterator()
Returns an iterator that has no elements.

static <T> ListIterator<T> emptyListIterator()
Returns a list iterator that has no elements.

There's methods to return empty collections too (List, Map, Set) as well
as singletons for List, Map and Set, but I think more folks know about
those. The above methods I listed are new with Java 1.7.


 
Reply With Quote
 
 
 
 
Daniele Futtorovic
Guest
Posts: n/a
 
      12-01-2012
On 28/11/2012 19:28, Eric Sosman allegedly wrote:
> On 11/28/2012 1:22 PM, Eric Sosman wrote:
>> [...]
>> If you do this sort of thing a lot write yourself a utility
>> class implementing Enumeration<T>, with a constructor that
>> takes an Iterator<T>. A companion class wrapping an Iterator<T>
>> around an Enumeration<T> is equally easy to write, and might
>> also be handy. (I'm a little surprised that Snoracle doesn't
>> provide such wrappers -- or maybe they do, but under names
>> that have escaped my notice.)

>
> Aha! Thanks to Jim Janney, I've just learned about the
> Collections#enumeration(Collection) method. It's perhaps a
> smidgen less general than enumeration(Iterator) would be, but
> only a smidgen.


That's been there for a while.

Unfortunately, there's no enumeration(Iterable) support. Iterable, being
a somewhat late addition, is overall poorly integrated, which is a pity.
Same thing goes for CharSequence.

--
DF.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re-using a simple type definition; with enumeration constraint andwithout enumeration constraint puvit82 XML 4 02-01-2008 03:46 PM
Convert Between Enumeration and Integer Values Olaf Petzold VHDL 4 11-28-2005 11:31 PM
How to convert from std::list<T*>::iterator to std::list<const T*>::iterator? PengYu.UT@gmail.com C++ 6 10-30-2005 03:31 AM
My idea for filtering an Enumeration or Iterator Robert Maas, see http://tinyurl.com/uh3t Java 8 07-28-2005 05:15 AM



Advertisments