快速的拼接String字符串

走着路睡觉
  • java
小于 1 分钟

StringJoiner joiner = new StringJoiner(",");
joiner.add("01").add("02").add("03");
String joinedString = joiner.toString(); // "01,02,03"


String joinedString = String.join(" - ", "04", "05", "06"); // "04 - 05 - 06"


List<String> strings = new LinkedList<>();
strings.add("Java");strings.add("is");
strings.add("cool");
String message = String.join(" ", strings);
//message returned is: "Java is cool"
上次编辑于:
贡献者: zhaojingbo
Loading...