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
LinkedHashSet will do the trick.
//output: 5,1,2,3,4
In Java 8:
Please note that the hashCode-equals contract for list members should be respected for the filtering to work properly.
It is possible to remove duplicates from arraylist without using HashSet or one more arraylist.
Try this code..
Output is
This three lines of code can remove the duplicated element from ArrayList or any collection.