Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

values in queue Java

Tags:

java

If I have a queue with strings as values How would I print all the values I was using:

System.out.println(queue.elements().toString().); 

But it prints java objects...?

Do I have to use a loop to print values of queue?

like image 454
edgarmtze Avatar asked Mar 24 '11 01:03

edgarmtze


1 Answers

Yes, you will need to use a loop however the loop can be simple like.

for(String s : queue) { 
  System.out.println(s.toString()); 
}

Actually, as long as it implements Iterable you should be able to do this type of foreach loop.

like image 93
Suroot Avatar answered Oct 01 '22 08:10

Suroot