Java Vector loop fails
Person indie = new Person(); Vector<Person> personList = new Vector<Person>(); //-Snip- while(nextPerson.equalsIgnoreCase("y")){ System.out.println("Name:"); indie.setName(scanner.next()); System.out.println("Gender (m/f):"); indie.setGender(scanner.next()); System.out.println("Age:"); indie.setAge(scanner.nextInt()); System.out.println("Weight:"); indie.setWeight(scanner.nextDouble()); System.out.println("Height:"); indie.setHeight(scanner.nextDouble()); personList.addElement(indie); System.out.println("Would you like to add another person?(y/n)"); nextPerson = scanner.next(); } for(int i = 0; i < personList.size();i++){ System.out.println("Name: " + personList.get(i).getName()); System.out.println("Gender: " + personList.get(i).getGender()); System.out.println("Age: " + personList.get(i).getAge()); System.out.println("Weight: " + personList.get(i).getWeight()); System.out.println("Height: " + personList.get(i).getHeight()); System.out.println("BMI: " + personList.get(i).calcBMI()); System.out.println("Assesment " + personList.get(i).assesBMI()); } This code only displays the last element of the vector for the times of its size and I don't know why it doesn't display the rest. It also doesnt work with the ForEach loop. None of the attributes that are set have any additional declaration besides "private". Could anybody help me out? Thanks!