| | |
Hi .Facing problem while displaying LinkedList (API) element using Iterator
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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 .
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 .
Java Syntax (Toggle Plain Text)
private static void callDisplay(LinkedList<Room> roomlist) { // TODO Auto-generated method stub ListIterator<Room> iter = roomlist.listIterator(); while ( iter.hasNext() ) { System.out.println("Came in"); Room r = iter.next(); r.toString(); } }
"The most important single aspect of software development is to be clear about what you are trying to build." - Bjarne Stroustrup
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
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
instead.
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
java Syntax (Toggle Plain Text)
System.out.println( r.toString() );
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. ![]() |
Other Threads in the Java Forum
- Previous Thread: Need help! (Simple programs...)
- Next Thread: java problem
Views: 583 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
actuate android api apple applet application arguments array arrays automation balls binary bluetooth business c++ chat class classes client code codesnippet collections component database defaultmethod doctype dragging draw ebook eclipse error event exception file fractal froglogic game givemetehcodez graphics gui helpwithhomework hql html ide image input integer intersect invokingapacheantprogrammatically j2me java javaprojects jmf jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie number numbers object oracle parameter php print problem program programming project recursion scanner screen server set size sms socket sort sql string sun swing swt tcp test threads time transfer tree udp windows






