我有这样定义的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.