-3

I know scala use stripMargin to create multiline,such as:

def catalog = s"""{
        |"table":{"namespace":"default", "name":"table1"},
        |"rowkey":"key",
        |"columns":{
          |"col0":{"cf":"rowkey", "col":"key", "type":"string"},
          |"col1":{"cf":"cf1", "col":"col1", "type":"boolean"},
          |"col2":{"cf":"cf2", "col":"col2", "type":"double"},
          |"col3":{"cf":"cf3", "col":"col3", "type":"float"},
          |"col4":{"cf":"cf4", "col":"col4", "type":"int"},
          |"col5":{"cf":"cf5", "col":"col5", "type":"bigint"},
          |"col6":{"cf":"cf6", "col":"col6", "type":"smallint"},
          |"col7":{"cf":"cf7", "col":"col7", "type":"string"},
          |"col8":{"cf":"cf8", "col":"col8", "type":"tinyint"}
        |}
      |}""".stripMargin

Does Java have so cool syntax ?

Thanks!

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Pookly
  • 103
  • 2
  • 15

1 Answers1

1

From java 13 you can use multiline java strings like:

class Foo { 
 public void bar() {    
   String txt = """      
     Some        
       Nested          
         Text        
       Is     
     Here      
   """;  
 }
}

For more please visit: https://www.jrebel.com/blog/using-text-blocks-in-java-13

prateek3636
  • 155
  • 1
  • 7