如何从Set和Comparator获取列表 [英] How get List from Set and Comparator
本文介绍了如何从Set和Comparator获取列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从Set
获取List
并根据给定的Comparator
进行排序的好"(以及为什么?)解决方案是什么?
What is the "good" (and why ?) solution to get a List
from a Set
and sorted against a given Comparator
?
推荐答案
Set<Object> set = new HashSet<Object>();
// add stuff
List<Object> list = new ArrayList<Object>(set);
Collections.sort(list, new MyComparator());
这篇关于如何从Set和Comparator获取列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文