I do not understand your question. You say you want to print lines, and then after some code that does not compile, you say: "But it prints java objects ...?" Strings are Java objects.
import java.util.*; public class Foo { public static void main(String[] args) { Queue<String> queue = new LinkedList<String>();
Launch, for example, java Foo apple banana pear . Output:
[apple, banana, pear] apple banana pear
If the problem is that you get the output as follows:
[ MyObject@498b5a73 , MyObject@5bdf59bd , MyObject@247cb66a ] MyObject@498b5a73 MyObject@5bdf59bd MyObject@247cb66a
Then your queue does not actually contain a string, and you forgot to override the toString() method in your class:
@Override public String toString() { return firstName + " " + lastName + ", " + quest + ", " + favoriteColor; }
There is no need to use a loop unless you [like, this, output, format] .
source share