我有一个如下所示的String列表,我想用用百里香分隔的逗号(,)将其转换为String。
List<String> scopeList = Arrays.asList("settings","locations","accounts","notifications");
我想这样简单地获取输出:
settings,locations,accounts,notifications
答案 0 :(得分:0)
尝试一下
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
答案 1 :(得分:0)
已通过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(",")));
}
}
输出:
设置,位置,帐户,通知
答案 2 :(得分:0)
您可以尝试一下。
List<string> scopeList= new List<string>() {
"settings","locations","accounts","notifications" };
var result = String.Join(",", scopeList);
答案 3 :(得分:0)
您可以使用此:
import org.apache.commons.lang3.StringUtils;
String result = StringUtils.join(scopeList, ",");
此外,在Java 8中,您可以使用 String.join :
String result = String.join(",", scopeList);
答案 4 :(得分:0)
尝试一下:
Day([DATE])<Day(DateTimeNow())-1