集册 Java实例教程 从Long的ArrayList中删除重复项

从Long的ArrayList中删除重复项

欢马劈雪     最近更新时间:2020-01-02 10:19:05

491
从Long的ArrayList中删除重复项

/*来自 
 n o w    j a v a  . c o m*/

//package com.nowjava;

import java.util.ArrayList;

import java.util.HashSet;

import java.util.Iterator;

import java.util.List;

import java.util.Set;


public class Main {

    public static ArrayList<Long> removeDuplicates(ArrayList<Long> a_master) {

        ArrayList<Long> a = new ArrayList<Long>(a_master);

        Set<Long> set = new HashSet<Long>();

        List<Long> newList = new ArrayList<Long>();

        for (Iterator<Long> iter = a.iterator(); iter.hasNext();) {

            Long element = iter.next();

            
展开阅读全文