🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #7626

[Beginner] How to create a list class..

#7626
From: Stefan Landgraf
Date: Thu, 14 Jun 2001 17:04
44 lines
2205 bytes
I probably made a stupid error, but cannot find it. I have an object Person
and a ListClass PersonList, which has a method hasMorePersons() and
nextPerson() to browse through the list. For storage i use a Vector. This is
the class:

public class PersonList {
 Vector vector = new Vector();
 public PersonList() {
      [.. Code to retrieve Person Data from DB..]
      while (RS.next()) {
        Person p = new Person();
        p.fname = RS.getString("fname");
        p.lname = RS.getString("lname");
        p.street = RS.getString("street_nr");
        p.plz  = RS.getString("pcode");
        p.city = RS.getString("city");
        addPerson(p);
      }
   }
  public void addPerson(Person p){
    vector.addElement(p);
  }
  public boolean hasMorePersons(){
    return vector.elements().hasMoreElements();
  }
   public Person nextPerson(){
    return  (Person)vector.elements().nextElement();
  }
}

But when using my list class with

    PersonList myList = new PersonList();

    while( myList.hasMorePersons() ){
      Person p = myList.nextPerson();
      System.out.println(p.fname + " " + p.lname);
    }

it always returns the same (the first object) in the list... :-(

Can anybody help, please?

Thanks alot! Stefan
Technical Details
Message-ID: <9gar3e$84r2q$1@ID-93315.news.dfncis.de>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!netnews.web.de!fu-berlin.de!uni-berlin.de!a812f.pppool.DE!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,d0bf796b0a1c05ef,start
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-06-14 10:15:13 PST
From: "Stefan Landgraf" <stefan_landgraf@gmx.de>
Newsgroups: borland.public.jbuilder.java.language
Subject: [Beginner] How to create a list class..
Date: Thu, 14 Jun 2001 19:04:29 +0200
Lines: 46
Message-ID: <9gar3e$84r2q$1@ID-93315.news.dfncis.de>
NNTP-Posting-Host: a812f.pppool.de (213.6.129.47)
X-Trace: fu-berlin.de 992538543 8547418 213.6.129.47 (16 [93315])
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!isdnet!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!netnews.web.de!fu-berlin.de!uni-berlin.de!a812f.pppool.DE!not-for-mail