Java multiline string

前端 未结 30 2912
醉梦人生
醉梦人生 2020-11-22 15:55

Coming from Perl, I sure am missing the \"here-document\" means of creating a multi-line string in source code:

$string = <<\"EOF\"  # create a three-l         


        
30条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 16:30

    With JDK/12 early access build # 12, one can now use multiline strings in Java as follows :

    String multiLine = `First line
        Second line with indentation
    Third line
    and so on...`; // the formatting as desired
    System.out.println(multiLine);
    

    and this results in the following output:

    First line
        Second line with indentation
    Third line
    and so on...
    

    Edit: Postponed to java 13

提交回复
热议问题