Converting a TreeSet to ArrayList?
问题 I have a TreeSet which contains > 100k objects. I have another method which requires ArrayList as an param. Is there any way I can accomplish this without iterating whole TreeSet and then adding each object manually to ArrayList ? 回答1: How about this: new ArrayList<T>(set); 回答2: ArrayList has a convenience method addAll that fits the bill nicely: final Set<Object> set = ... List<Object> list = new ArrayList<Object>(someBigNum); list.addAll(set); 来源: https://stackoverflow.com/questions/9322405