当前位置: 技术问答>java相关
Java怎样分割字符串,有没有Perl或者VB一样的Split方法?
来源: 互联网 发布时间:2015-03-04
本文导语: 比如: String a="1,2,3,4"; String[] b={}; b=Split(a); | String a = "1,2,3,4"; StringTokenizer st = new StringTokenzier(a,",");//这里的字符串的每一个字符都是分隔符 String[] b = new String[st.countTokens()]; int i = 0; w...
比如:
String a="1,2,3,4";
String[] b={};
b=Split(a);
String a="1,2,3,4";
String[] b={};
b=Split(a);
|
String a = "1,2,3,4";
StringTokenizer st = new StringTokenzier(a,",");//这里的字符串的每一个字符都是分隔符
String[] b = new String[st.countTokens()];
int i = 0;
while(st.hasMore()) {
b[i++] = st.nextToken();
}
StringTokenizer st = new StringTokenzier(a,",");//这里的字符串的每一个字符都是分隔符
String[] b = new String[st.countTokens()];
int i = 0;
while(st.hasMore()) {
b[i++] = st.nextToken();
}
|
import java.util.StringTokenizer;
public class Sample{
public static void main(String argv[]){
String a="1,2,3,4";
StringTokenizer st = new StringTokenizer(a,",");
while(st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
}
}
public class Sample{
public static void main(String argv[]){
String a="1,2,3,4";
StringTokenizer st = new StringTokenizer(a,",");
while(st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
}
}