java数组字符串合并 java字符串的合并
人气:1想了解java字符串的合并的相关内容吗,在本文为您仔细讲解java数组字符串合并的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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);
}
}
加载全部内容