1 Star 2 Fork 1

csbooks/OnJava8-Code

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
ImmutableStrings.java 708 Bytes
Copy Edit Raw Blame History
Bruce Eckel authored 2016-12-31 09:23 +08:00 . Date change
// references/ImmutableStrings.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// Demonstrating StringBuilder
public class ImmutableStrings {
public static void main(String[] args) {
String foo = "foo";
String s = "abc" + foo + "def"
+ Integer.toString(47);
System.out.println(s);
// The "equivalent" using StringBuilder:
StringBuilder sb =
new StringBuilder("abc"); // Creates String
sb.append(foo);
sb.append("def"); // Creates String
sb.append(Integer.toString(47));
System.out.println(sb);
}
}
/* Output:
abcfoodef47
abcfoodef47
*/
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/javabook/OnJava8-Code.git
git@gitee.com:javabook/OnJava8-Code.git
javabook
OnJava8-Code
OnJava8-Code
master

Search