java字符串的合并_java

分享到:
答:import java.util.*;

class test
{
public static void main(String[] args)
{
String str1="001,002,003,004,006",str2 = "001,002,005";
String str="";
TreeSet ts = new TreeSet();

StringTokenizer st = new StringTokenizer(str1,",");
while (st.hasMoreTokens())
{
ts.add(st.nextToken());
}

st = new StringTokenizer(str2,",");
while (st.hasMoreTokens())
{
ts.add(st.nextToken());
}

Iterator it = ts.iterator();

while(it.hasNext())
str=str+it.next()+",";

System.out.println(str);
}
}
昵    称:
验证码:

相关文档: