Java String new line

前端 未结 17 832
情歌与酒
情歌与酒 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:46

    Platform-Independent Line Breaks

    finalString = "physical" + System.lineSeparator() + "distancing";
    System.out.println(finalString);
    

    Output:

    physical
    distancing
    

    Notes:
    Java 6: System.getProperty("line.separator")
    Java 7 & above: System.lineSeparator()
    

提交回复
热议问题