Java中实现String字符串用逗号隔开

发布时间 2023-04-18 15:26:36作者: 多言

public static void main(String[] args) throws Exception{
String strText = "421542";
String information = "";
int start = 0;
int end = 1;
String digit = "";
int count = strText.length();
for (int i = 0; i < count; i++) {
information = strText.substring(start,end);
digit = digit+information+",";
start++;
end++;
}
System.out.println(digit.substring(0,digit.length()-1));

//4,2,1,5,4,2
}