🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.java
Article #1115

Re: Enumerators and Vectors...

#1115
From: Tom Davies
Date: Sun, 25 Jul 1999 00:00
49 lines
2494 bytes
Steve,
	Your code looks correct -- it would be faster if you used a
StringBuffer rather than a String, but it looks as though it works.

	You don't need to write hasMoreElements() or nextElement(). The
function Vector.elements() returns an implementation of the Enumeration
interface.

Tom


Steve Hewitt wrote:
> 
> Can anyone please help with the following...
> 
> I have been asked to write a class called 'ItemSet' which holds a number of
> Item objects (already defined).
> 
> The Items are stored within a vector and typical methods are 'addItem()',
> 'removeItem()', 'getItems()' etc, etc.
> 
> I have been told to use the Enumerator class but I am having a few problems.
> What exactly do I need to include within the ItemSet class to make use of
> the Enumerator class? I understand that it is used to iterate through
> elements of an object and that I must declare two methods - public boolean
> hasMoreElements() and public Object nextElement() - but how does it all fit
> together?
> 
> As an example I have a method which should return all Items that are
> contained within the set. I have coded this to be :
> 
> // returns a String of relevant set details
> public String toString()
> {
>     String setDetails = new String();
> 
>     for (Enumeration e = items.elements() ; e.hasMoreElements() ;)
>         setDetails = setDetails + e.nextElement() + '\n';
> 
>     return setDetails;
> }
> 
> where 'items' is the Vector containing all of the Items in the set. What should the methods hasMoreElements and nextElement contain? and is the implementation of the method above correct?
> 
> Any help would be much appreciated.
> 
> Steve
> steve@bert44.freeserve.co.uk
> hewitts@abs-ltd.com
Technical Details
Message-ID: <379B03FD.ECFDB718@smartchat.net.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7ncojq$bf6$1@news8.svr.pol.co.uk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,e1c8263d0c15df19
X-Google-Attributes: gid10d6db,public
From: Tom Davies <tom@smartchat.net.au>
Subject: Re: Enumerators and Vectors...
Date: 1999/07/25
Message-ID: <379B03FD.ECFDB718@smartchat.net.au>
X-Deja-AN: 504924016
Content-Transfer-Encoding: 7bit
References: <7ncojq$bf6$1@news8.svr.pol.co.uk>
To: Steve Hewitt <Steve@bert44.freeserve.co.uk>
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@connect.com.au
X-Trace: merki.connect.com.au 932869817 7102 210.8.3.199 (25 Jul 1999 02:30:17 GMT)
Organization: Customer of Connect.com.au Pty. Ltd.
Mime-Version: 1.0
NNTP-Posting-Date: 25 Jul 1999 02:30:17 GMT
Newsgroups: aus.computers.java