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 .

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();
			
		}
		
	}

Recommended Answers

All 2 Replies

The r.toString() returns a String, it does not print. You need to call System.out.println() with argument r or r.toString()

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

System.out.println( r.toString() );

instead.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.