Skip to Content
0
Former Member
Dec 11, 2006 at 11:47 AM

Iterate through ArrayList

102 Views

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