Alex Rivera | Logout

How can I print a string adding newlines in Java?

Asked 2011-10-20T09:19:03.330
162

I have a string like

"I am a boy".

I would like to print it this way

"I 
am 
a
boy".

Can anybody help me?

Edit
Report

1 Answer

6

If you simply want to print a newline in the console you can use \n for newlines.

If you want to break text in Swing components you can use HTML and its <br>:

String str = "<html>first line<br>second line</html>";
answered 2011-10-20T09:21:24.317

Your Answer