算法之去掉vetor集合中的重复元素

public class DropRepetition {
public static void main(String[] args) {
Vector<String> v = new Vector<String>();
v.add("1");
v.add("1");
v.add("2");
v.add("2");
v.add("3");
v.add("3");
dropRepetition1(v);
dropRepetition2(v);
} private static Vector<String> dropRepetition1(Vector<String> v) {
//创建新的Vector对象
Vector<String> newV = new Vector<String>();
for (String str : newV) {
if(!newV.contains(str))
newV.add(str);
}
return newV;
}
private static HashSet<String> dropRepetition2(Vector<String> v) {
//构造新的HashSet
HashSet<String> set = new HashSet<String>(v);
return set;
}
}
上一篇:Elasticsearch笔记五之java操作es


下一篇:Linux之软链接与硬链接