Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
与在 java6.
例如。在以下两行代码中,哪一行执行得更快:
String str = "One" + '\"'
或者
String str = "One" + """
我猜 String 到 String 的连接性能会好一点,因为他们不需要转换为 Character 并在其上调用 toString() 方法。
Java 语言规范: 15.18.1.1 字符串转换
任何类型都可以通过字符串转换转换为String类型。原始类型 T 的值 x 首先被转换为引用值,就好像通过将其作为参数提供给适当的类实例创建表达式:• 如果 T 是布尔值,则使用 new Boolean(x)。• 如果T 是char,则使用new Character(x)。 ...