列表实现既是一个设置列表(序列)? [英] List implementation that is both a Set a List (sequence)?

查看:137
本文介绍了列表实现既是一个设置列表(序列)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以扩展LinkedList并实现Set,所以我有一个没有重复的列表。我想知道这样的实现是否已经不存在?

I'm in the position of extending LinkedList and implement Set, so that I have a list with no duplicates. I'm wondering if such an implementation doesn't exist already?

我计划做的是覆盖 add(e) 方法首先查找元素,如果存在,不要添加它。类似:

All I'm planning to do is to override the add(e) method to first look-up the element, and if present don't add it. Something like:

add(E){
   if(get(E) == null) super.add(E);
}


推荐答案

但是,您可以查看 SetUniqueList 常见收藏,可能符合您要查找的内容。

However, you can take a look at SetUniqueList from the Common Collections which may be along the lines of what you are looking for.

这篇关于列表实现既是一个设置列表(序列)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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