数组合并的问题

zg6002 2008-03-07 11:36:10
请问一下,现有五个String[],有什么好的方法能合并成为一个没有重复值的String[]
...全文
108 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zg6002 2008-03-08
  • 打赏
  • 举报
回复
给分了
zg6002 2008-03-08
  • 打赏
  • 举报
回复
我指的数组是不定数量的!
hmsuccess 2008-03-07
  • 打赏
  • 举报
回复
AarryList
Vector
kkkdyc 2008-03-07
  • 打赏
  • 举报
回复

public static void main(String[] args) {
HashSet s = new HashSet();

String[] str1 = new String[]{"111","222","333"};
String[] str2 = new String[]{"111","444","555"};

for(int i = 0;i<str1.length;i++){
s.add(str1[i]);
}

for(int i = 0;i<str2.length;i++){
s.add(str2[i]);
}

Object[] str3 = s.toArray();

System.out.println(s.size());
for(int i = 0;i<str3.length;i++){
System.out.println(str3[i]);
}
}
//输出结果
5
555
222
333
111
444

bt_lose 2008-03-07
  • 打赏
  • 举报
回复
Hashset来做做看
临远 2008-03-07
  • 打赏
  • 举报
回复
都放进一个set里,然后再从set生成个String[]出来。

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧