on 12-11-2006 11:47 AM
Hi, just got a simple question concering the iteration of an arraylist:
(left out the not relevant code blocks)
<b>Contents of login.data</b>
-
Marry;Poppins;passwort;1. September 2006
Peter;Lustig;wohnwagen;1. September 2005
<b>Login Bean</b>
-
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.ListIterator;
public class LoginBean extends ArrayList {
/**
*
* Variablendefinitionen
*
*/
Login loginListe;
public LoginBean() {
checkLoginExistance;
}
public boolean checkLoginExistance() {
ListIterator li = this.listIterator();
while (li.hasNext()) {
String vorname = this.loginListe.getVorname();
String nachname = this.loginListe.getNachname();
String passwort = this.loginListe.getPasswort();
String letzterLogin = this.loginListe.getLetzterLogin();
System.out.println("Vorname: "+vorname);
System.out.println("Nachname: "+nachname);
System.out.println("Passwort: "+passwort);
System.out.println("LastLogin: "+letzterLogin);
li.next();
}
boolean result = false;
return result;
}
}
The problem occurs during the hasNext-Iteration Block
while (li.hasNext()) {
..}
The two elements should be iterated and printed out on console, but unfortunately just the 2nd element is printed out twice:
<b>Console Output:</b>
-
Vorname: Peter
Nachname: Lustig
Passwort: wohnwagen
LastLogin: 1. September 2005
Vorname: Peter
Nachname: Lustig
Passwort: wohnwagen
LastLogin: 1. September 2005
Message was edited by:
Lars Paetzold
Something missing in your code.
Where your assinging the value to <b>this.loginListe</b> ?
And also hasNext() returns only the availability of the data in List, you need to change code to in the begging of while loop.
this.loginListe = (Login)li.next();
Regards
Abhilash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.