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

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
}

posted on 2023-04-18 15:24  多言  阅读(335)  评论(0编辑  收藏  举报

导航