java字符串的合并
发布时间:2016-12-28 来源:查字典编辑
摘要:答:importjava.util.*;classtest{publicstaticvoidmain(String[]args){Strin...
答: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);
}
}