加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

如何从Array中添加SortedSet项?

发布时间:2020-12-14 23:34:09 所属栏目:Java 来源:网络整理
导读:我有这样定义的SortedSet: SortedSetRatedMessage messageCollection = new TreeSetRatedMessage(new Comp()); 我有一个RatedMessage []数组 我必须使用数组,因为集合错过了序列化功能,现在我需要重新构建它. 有没有一种快速的方法可以将数组中的所有项目再
我有这样定义的SortedSet:
SortedSet<RatedMessage> messageCollection = new TreeSet<RatedMessage>(new Comp());

我有一个RatedMessage []数组

我必须使用数组,因为集合错过了序列化功能,现在我需要重新构建它.

有没有一种快速的方法可以将数组中的所有项目再次添加到集合中?

解决方法

Collections.addAll(messageCollection,array);

功能与迈克尔的答案完全相同,但正如javadoc所说:

Adds all of the specified elements to the specified collection. Elements to be added may be specified individually or as an array. The behavior of this convenience method is identical to that c.addAll(Arrays.asList(elements)),but this method is likely to run significantly faster under most implementations.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读