java - 如何在 Java 中创建多行字符串?
问题描述
我知道 scala 使用 stripMargin 创建多行,例如:
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
Java有这么酷的语法吗?
谢谢!
解决方案
从 java 13 开始,您可以使用多行 java 字符串,例如:
class Foo {
public void bar() {
String txt = """
Some
Nested
Text
Is
Here
""";
}
}
更多信息请访问:https ://www.jrebel.com/blog/using-text-blocks-in-java-13
推荐阅读
- sql - 无法在 SQL Server 中使用 LAG 函数检索数据
- c - 从 'int*' 到 'unsigned int*' 的无效转换 [-fpermissive]
- android - 在 Android Recyclerview 中处理多个按钮单击并将响应存储在 Array 或 ArrayList 中
- php - 点击登录按钮后页面没有变化?
- javascript - 如何在 Visual Studio 的 Node.js 项目中将错误设置为警告
- javascript - 如果选中一个复选框,如何从多个复选框中获取值?
- c++ - 是否可以在不使用 Base 复制构造函数的情况下在 Derived 类中使用复制构造函数?
- javascript - Power BI 配置对最终用户可见
- php - 将 x 天数添加到给定日期,但它将天数作为月份并进行计算。帮我改一下格式
- c - Xcode 调试器弄乱了输入