How to insert a new line in strings in Android

Reed picture Reed · Jun 17, 2011 · Viewed 142.3k times · Source

This may seem like a stupid question, but I've been searching and can't find an answer.

I'm creating an android application and within it there is a button that will send some information in an email, and I don't want to have everything all in one paragraph.

Here's what my app is doing for the putExtra for the email's body:

I am the first part of the info being emailed. I am the second part. I am the third part.

Here's what I want it to do:

I am the first part of the info being emailed.
I am the second part.

I am the third part.

How would I put a new line into a string or with the putExtra method to accomplish that?

Thank you.

Answer

user824013 picture user824013 · Aug 24, 2011

Try:

String str = "my string \n my other string";

When printed you will get:

my string
my other string