Java String new line

前端 未结 17 830
情歌与酒
情歌与酒 2020-11-28 23:17

I have string like

\"I am a boy\".

I want to print like this way

\"I 
am 
a
boy\".

Can anybody help me?<

17条回答
  •  春和景丽
    2020-11-28 23:30

    To make the code portable to any system, I would use:

    public static String newline = System.getProperty("line.separator");
    

    This is important because different OSs use different notations for newline: Windows uses "\r\n", Classic Mac uses "\r", and Mac and Linux both use "\n".

    Commentors - please correct me if I'm wrong on this...

提交回复
热议问题