I have an ArrayList<String>
, and I want to remove repeated strings from it. How can I do this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Code:
Note: Definitely, there will be memory overhead.
Although converting the
ArrayList
to aHashSet
effectively removes duplicates, if you need to preserve insertion order, I'd rather suggest you to use this variantThen, if you need to get back a
List
reference, you can use again the conversion constructor.If you want to preserve your Order then it is best to use LinkedHashSet. Because if you want to pass this List to an Insert Query by Iterating it, the order would be preserved.
Try this
This conversion will be very helpful when you want to return a List but not a Set.