我知道 StringBuilder 应该用于连接多个字符串而不是使用 +。我的问题是截止点是什么?
有人告诉我,如果连接 4 个或更多字符串,您应该使用 StringBuilder.append(),对于其他任何内容,请使用 +。 是这样吗?或者是 stringbuilder 的效率比 4 更高的点?
最佳答案
从 Java 1.5 开始,当在源代码中使用 +
时,编译器会自动使用 StringBuilder
。
The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method.
关于Java - 有多少字符串连接应该提示使用 StringBuilder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15502850/