如何把逗号分隔的字符串转换成数组
1个回答
2017-08-04
展开全部
public class StrSplit{
public static void main(String[] args) {
String orgStr="ab,b,c,d,e,f";
StringTokenizer tokener = new StringTokenizer(orgStr,",");
String [] result = new String[tokener .countTokens()];
int i=0;
while(tokener. hasMoreTokens ())
{
result[i++]=tokener.nextToken();
}
for(int a = 0;a<result.length;a++){
System.out.print(result[a]+"\t");
}
}
}
public static void main(String[] args) {
String orgStr="ab,b,c,d,e,f";
StringTokenizer tokener = new StringTokenizer(orgStr,",");
String [] result = new String[tokener .countTokens()];
int i=0;
while(tokener. hasMoreTokens ())
{
result[i++]=tokener.nextToken();
}
for(int a = 0;a<result.length;a++){
System.out.print(result[a]+"\t");
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询