public void createPersons() { Random rand = new Random(); for(int index = 0; index < persons.length; index++) { Person person = new Person(rand.nextInt(maxAge), persons[index]); setOfPersons.add(person); } } public void printPersons() { for(Iterator<Person> r = setOfPersons.iterator(); r.hasNext();) { System.out.println(r.next().getName() + " is " + r.next().getAge() + " years old"); } System.out.println(setOfPersons.size()); }
setOfPersons is a TreeSet, persons[] is an array of strings that contains 10 names. Why printPersons() prints only the half names of setOfPersons?
Note. I do get the size of the TreeSet as 10...