可重复排序的Java集合 [英] Sortable Java collection without duplicates

查看:151
本文介绍了可重复排序的Java集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找可排序(我的意思是排序初始化后和使用Comparator多次)Java类集合没有重复。是否有更纯的解决方案比编写代码不透明,并防止例如一些ArrayList添加另一个对象与已经存在的相同的值?



编辑1:
我应该添加一些关于排序的解释。我需要用不同的比较器(实现的多样性)多次对这组值进行排序。

解决方案

http://docs.oracle.com/javase/6/docs/api/java/util/Set.html\">设置!常见的实现是 HashSet TreeSet 。后者保留项目在执行 SortedSet 时的顺序。 p>

I am searching for sortable (I mean sorting after initialization and many times using Comparator) Java class collection without duplicates. Is there any more pure solution than writing code which will opaque and prevent for example some ArrayList for adding another object with the same value that already exists?

Edit 1: I should add some explanation about sorting. I need to sort this set of values many times with different comparators (diversity of implementations).

解决方案

Use a Set! The common implementations are HashSet and TreeSet. The latter preserves the order of items as it implements SortedSet.

这篇关于可重复排序的Java集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆