My understanding is that the toString method for an ArrayList will call
the respective toString method for each element of the ArrayList.
However, in the below code, calling guests.toString() gives no output.
I think that I must be doing something wrong that the printGuests method
must even exist, but I'm not sure what -- I just want to print all the
guests.
thufir@[EMAIL PROTECTED]
thufir@[EMAIL PROTECTED]
cat src/a00720398/labs/Lab2.java
package a00720398.labs;
import a00720398.data.*;
import java.util.*;
public class Lab2
{
private static Guests guests = new Guests();
public static void loadGuests() {
for (int i=0; i<9; i++) {
Guest guest = new Guest();
guests.add(guest);
}
}
public static void printGuests() {
for (Guest guest : guests) {
System.out.println(guest);
}
}
public static void main (String[] args)
{
loadGuests();
printGuests(); //prints out the guests
//guests.toString; //gives no output at all.why?
}
}
thufir@[EMAIL PROTECTED]
thufir@[EMAIL PROTECTED]
cat src/a00720398/data/Guests.java
package a00720398.data;
import java.util.*;
public class Guests extends ArrayList <Guest>
{
}
thufir@[EMAIL PROTECTED]
thufir@[EMAIL PROTECTED]
thanks,
Thufir