简体   繁体   中英

How to compare two large array lists efficient in java

so I have 2 large arraylists of objects of A 500k and B 900k in size and I want to create a 3rd list (c) of all the dups of A in B.

So I've been doing

    for(obj as:B)
    {

        if(!A.contains(as.getA()))
        {
            C.add(as);
        }

    }

But this takes quite a bit of time to process. Would maps or sets be quicker or any other suggestions? Thanks.

Use HashSet collection

List<MyClass> myList = new ArrayList<MyClass>();
myList.addAll(listA);
myList.addAll(listB);

Set<MyClass> mySet = new HashSet<MyClass>(myList);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM