用 java.util.StringTokenizer 的解决办法String str=new String(); str="abc,def,ghi";StringTokenizer st = new StringTokenizer(str, ","); ArrayList ss = new ArrayList(); while (st.hasMoreTokens()) { ss.add(st.nextToken()); }for (int i = 0; i < ss.size(); ++i) { System.out.println(ss.get(i)); }
用自己写代码查找的方法: String str=new String(); str="abc,def,ghi";ArrayList ss = new ArrayList();int i = 0; int j = str.indexOf(","); while (j >= 0) { ss.add(str.substring(i, j)); i = j + 1; j = str.indexOf(",", i); } ss.add(str.substring(i));
str="abc,def,ghi";StringTokenizer st = new StringTokenizer(str, ",");
ArrayList ss = new ArrayList();
while (st.hasMoreTokens()) {
ss.add(st.nextToken());
}for (int i = 0; i < ss.size(); ++i) {
System.out.println(ss.get(i));
}
String str=new String();
str="abc,def,ghi";ArrayList ss = new ArrayList();int i = 0;
int j = str.indexOf(",");
while (j >= 0) {
ss.add(str.substring(i, j));
i = j + 1;
j = str.indexOf(",", i);
}
ss.add(str.substring(i));