0 votes
1 view
in Java by (3.5k points)
How do I get a platform-dependent newline in Java? I can’t use "\n" everywhere.

1 Answer

0 votes
by (46.1k points)

If you don't want to use the line separator property ("\n"), you can try string format and use %n (works for Java 1.5 or above)

Example:

Calendar c = ...;

String s = String.format("Duke's Birthday: %1$tm %1$te,%1$tY%n", c); \

String s2 = String.format; 

// %% becomes %    

// and `%n` becomes a newline 

Click here for more details.

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
asked Aug 12, 2019 in Java by Anvi (10.2k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...