Cannot find a solution to seem to be a simple question. For example, I have a string with LineBreak ”a\na”. The System.out.println output of this string shows 2 lines. However, I need to show the output in exactly the same form, i.e. “a\na”. How to achieve this?
Share
You need to escape your
\nwith an extra backslash..Use: –
"a\\na"to get\nin your output..Or, you can also take a look at :-
Apache CommonsStringEscapeUtils#escapeJavawhich will automatically excape all the specialescape sequenceswith an extra backslash..This will print: –
a\nb\r\t