我想将字符串与“,”一起从2到6。当我执行下面的代码时,我得到了输出,但是它以逗号开头。
String name="";
String s = "1,two,three,four,five,six,seven"; //this is a sample string, original string might contain more words separated by ","
String[] split = s.split(",");
System.out.println("Splitted Length: " +split.length);
if(split.length>2) {
for(int i=1; i<split.length-1;i++) {
name = name+","+split[i];
}
}
System.out.println(name);
输出:
Splitted Length: 7
,two,three,four,five,six
如何避免第一个逗号
DIEA
FFIVE
相关分类