Hi .Facing problem while displaying LinkedList (API) element using Iterator

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Dec 2007
Posts: 18
Reputation: Aashath is an unknown quantity at this point 
Solved Threads: 5
Aashath's Avatar
Aashath Aashath is offline Offline
Newbie Poster

Hi .Facing problem while displaying LinkedList (API) element using Iterator

 
0
  #1
Oct 22nd, 2008
Hi

I have a LinkedList of class called Room. Now i want display elements that i stored in that class . i also implemented toString() in my Room class which returns string.

The code i tried is below but its not working . i dont know the reason . can anyone help me .
  1. private static void callDisplay(LinkedList<Room> roomlist) {
  2. // TODO Auto-generated method stub
  3. ListIterator<Room> iter = roomlist.listIterator();
  4. while ( iter.hasNext() )
  5. {
  6. System.out.println("Came in");
  7. Room r = iter.next();
  8. r.toString();
  9.  
  10. }
  11.  
  12. }
"The most important single aspect of software development is to be clear about what you are trying to build." - Bjarne Stroustrup
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Hi .Facing problem while displaying LinkedList (API) element using Iterator

 
0
  #2
Oct 22nd, 2008
The r.toString() returns a String, it does not print. You need to call System.out.println() with argument r or r.toString()
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 812
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: Hi .Facing problem while displaying LinkedList (API) element using Iterator

 
0
  #3
Oct 22nd, 2008
When you say it's not working, are you getting an error message? Does the string "Came in" print? If the answer is no to both questions then there are no Room objects in your LinkedList. Try a call to roomList.size() to see how many are Room objects exist in your list.

If you are getting the string "Came in" printed, then the problem is that you are just writing r.toString() - you don't actually do anything with that call like print it. Try
  1. System.out.println( r.toString() );
instead.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum


Views: 584 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC