StringTokenizer使用

package test;

import java.util.Arrays;
import java.util.StringTokenizer;

public class Bycomma {

public static String[] splitStringByComma(String source){
if(source==null||source.trim().equals("")){
return null;
}
StringTokenizer commaToker = new StringTokenizer(source,
",");
String[] result = new String[commaToker.countTokens()];
int i=0;
while(commaToker.hasMoreTokens()){
result<i> = commaToker.nextToken();
i++;
}
return result;
}
public static void main(String[] args) {
String[] s = Bycomma.splitStringByComma(
"5,56,2,45,7,1,54");
int[] ii = new int[s.length];
for(int j=0;j<s.length;j++){
ii[j] = Integer.parseInt(s[j]);
}
Arrays.sort(ii);
//asc
for(int i=0;i<ii.length;i++){
System.out.println(ii<i>);
}

//desc
for(int i=(ii.length-1);i>=0;--i){
System.out.println(ii<i>);
}

StringTokenizer token = new StringTokenizer(
"3-343-bc-sdf-sd","-");
String[] tokens = new String[token.countTokens()];
int i=0;
while(token.hasMoreTokens()){
tokens<i> = token.nextToken();
System.out.println(tokens<i>);
i++;
}
}

}
lunzi   2008-03-09 23:43:33 评论:1   阅读:1087   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog