Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: ArrayList.t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 11 Topic 15990 of 16466
Post > Topic >>

Re: ArrayList.toString versus iterating through the ArrayList

by xinxin <jnzhouxinxin@[EMAIL PROTECTED] > Apr 20, 2008 at 04:41 AM

On 4=D4=C219=C8=D5, =CF=C2=CE=E75=CA=B141=B7=D6, thufir
<hawat.thu...@[EMAIL PROTECTED]
> wrote:
> 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;
> im****t a00720398.data.*;
> im****t java.util.*;
>
> public class Lab2
> {
>
>         private static Guests guests =3D new Guests();
>
>         public static void loadGuests() {
>                 for (int i=3D0; i<9; i++) {
>                         Guest guest =3D 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;
> im****t java.util.*;
>
> public class Guests extends ArrayList <Guest>
> {
>
> }
>
> thufir@[EMAIL PROTECTED]
> thufir@[EMAIL PROTECTED]
>
> thanks,
>
> Thufir

do you overwrite the toString method ,if not it will return the
address of object in the main memery.so overwrite the toString method
 




 11 Posts in Topic:
ArrayList.toString versus iterating through the ArrayList
thufir <hawat.thufir@[  2008-04-19 09:41:29 
Re: ArrayList.toString versus iterating through the ArrayList
Hendrik Maryns <gtw37b  2008-04-19 12:18:54 
Re: ArrayList.toString versus iterating through the ArrayList
Lew <lew@[EMAIL PROTEC  2008-04-19 09:18:21 
Re: ArrayList.toString versus iterating through the ArrayList
thufir <hawat.thufir@[  2008-04-19 22:44:33 
Re: ArrayList.toString versus iterating through the ArrayList
Lew <lew@[EMAIL PROTEC  2008-04-19 22:52:07 
Re: ArrayList.toString versus iterating through the ArrayList
Roedy Green <see_websi  2008-04-20 10:37:38 
Re: ArrayList.toString versus iterating through the ArrayList
Roedy Green <see_websi  2008-04-20 10:39:47 
Re: ArrayList.toString versus iterating through the ArrayList
xinxin <jnzhouxinxin@[  2008-04-20 04:41:09 
Re: ArrayList.toString versus iterating through the ArrayList
Lew <lew@[EMAIL PROTEC  2008-04-20 09:36:58 
Re: ArrayList.toString versus iterating through the ArrayList
thufir <hawat.thufir@[  2008-04-20 20:36:09 
Re: ArrayList.toString versus iterating through the ArrayList
thufir <hawat.thufir@[  2008-04-20 20:38:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 6 10:54:13 CDT 2008.