首页 > 编程 > Java > 正文

java字符串的合并

2019-11-26 16:20:16
字体:
来源:转载
供稿:网友
答: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);
}
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表