Java equivalent of Python repr()?

后端 未结 9 1868
醉酒成梦
醉酒成梦 2020-12-18 18:18

Is there a Java method that works like Python\'s repr? For example, assuming the function were named repr,

\"foo\\n\\tbar\".repr()

would re

9条回答
  •  隐瞒了意图╮
    2020-12-18 19:13

    Use the static method escapeJava from the StringEscapeUtils class in Apache Commons Text.

    String repr = "\"" + StringEscapeUtils.escapeJava(myString) + "\"";
    

提交回复
热议问题