数组转字符串, 字符串转数组

2024-07-27  本文已影响0人  xueyueshuai

使用逗号作为分隔符分割字符串

String str = "a,b,c";
String[] parts = str.split(",");

使用 String.join 方法

// 方式1
List<String> items = Arrays.asList("a", "b", "c");
String joined = String.join(",", items);
System.out.println(joined);  // 输出: a,b,c

// 方式2
List<String> items = Arrays.asList("a", "b", "c");
String joined = items.stream().collect(Collectors.joining(","));
上一篇 下一篇

猜你喜欢

热点阅读