Languages
[Edit]
EN

Java – how to add new line char in String?

10 points
Created by:
illona
526

1. Overview

Edit

In java we can use direct new line char or we can use method which gives us platform dependent new line character.

In this post we have 2 examples.

First one with new line character used explicitly.

Second one uses most popular method in java to get platform dependent new line character System.lineSeparator().

New line character on most popular operating systems

Operating System Name New line character
Windows \r\n
Linux / Unix \n
MacOS \n

2. Example 1

Edit

Output:

3. Example 2

Edit

Output:

See also

Edit
  1. Java - how to get new line character for given platform eg Windows, Linux or MacOS - platform dependent?

References

Edit
  1. Newline - wiki
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join