看这儿!!!

3yyy (锅碗瓢盆铲1个都不能)
本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
import java.util.*;

public class TestTokenization {
private static List tokenize(String str, String dms) {
ArrayList list = new ArrayList( );
StringTokenizer tok = new StringTokenizer(str, dms);
while (tok.hasMoreTokens()) {
list.add(tok.nextToken());
}
return list;
}

private static void refresh(List list, int position, String s) {
if (position >= list.size() ) {
return;
}
String temp = (String) list.get(position);
if (temp.endsWith(s)) {
temp = temp.substring(0, temp.indexOf(s))
+ (String) list.get(position + 1);
list.set(position, temp);
list.remove(position + 1);
}
refresh(list, ++position, s);
}

private static void prt(List list) {
Iterator it = list.iterator();
while (it.hasNext()) {
System.out.print(it.next() + " ");
}
}
public static void main(String[] args) {
String s = "abc\\|ef|gh|lmn\\|\\zx|yw";
List list = tokenize(s, "|");
prt(list);
System.out.println("");
refresh(list, 0, "\\");
prt(list);
}
}
更多精彩文章及讨论,请光临枫下论坛. 网址: rolia.net/zh
(#370237@0)
2002-2-15 -05:00

回到话题: Java TEST!!

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论

URL:   
http://www.rolia.net/zh/post.php?f=0&p=370237