【原创】Java小应用:将以逗号隔开的字符串数组按照给定的长度换行
程序源码:
public String getSplitStr(int num)
{
StringBuffer buf = new StringBuffer();
int i=0;
for (Object o : item) {
i++;
String temp="";
if(o==null)
{
temp="";
}else
{
temp=o.toString();
}
if(i%num==0)
{
buf.append(temp);
buf.append("\r");
}else
{
buf.append(temp);
buf.append(",");
}
}
return buf.toString();
}
输入item为:【a,b,c,d,e,f】 时,设定num=2,输出为:
a,b
c,d
e,f
谨记大邦~~~~~
浙公网安备 33010602011771号