简体   繁体   中英

Can I filter out duplicates within an array list using hashset in Java without distorting the order of the array?

I was wondering how I could return an array list in Java but filter out any duplicates that come from my object? I've heard the best way to do this is by using a hashset is this true or is there a better implementation? The reason I am skeptical about using hashset is I have heard it distorts the order of the array which is not what I want.

What you are are looking for is a Collection that maintains insertion order and does not allow duplicates.

Thankfully, there is one available in the form of a LinkedHashSet

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