我有一个类似下面给出的字符串列表,我想把它转换成用胸腺叶分隔的逗号(,)。
List<String> scopeList = Arrays.asList("settings","locations","accounts","notifications");我想简单地像这样得到输出:
settings,locations,accounts,notifications发布于 2019-09-04 15:37:42
尝试此
ArrayList<String> list = new ArrayList<>();
list.add("Java");
list.add("Spring");
list.add("Javascript");
StringJoiner sj = new StringJoiner(",");
list.forEach(sj::add);
System.out.println(sj);输出: Java、Spring、Javascript
发布于 2019-09-04 15:39:42
已使用CompileJava检查
//*******************************************************************
// Welcome to CompileJava!
// If you experience any issues, please contact us ('More Info') -->
//*******************************************************************
import java.util.*;
import java.util.stream.*;
// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
List<String> scopeList = Arrays.asList("settings","locations","accounts","notifications");
System.out.print(scopeList.stream().collect(Collectors.joining(",")));
}
}输出:
设置、位置、帐户、通知
发布于 2019-09-04 15:41:33
你可以试试这个。
List<string> scopeList= new List<string>() {
"settings","locations","accounts","notifications" };
var result = String.Join(",", scopeList);https://stackoverflow.com/questions/57783504
复制相似问题