I have two ArrayList
objects with three integers each. I want to find a way to return the common elements of the two lists. Has anybody an idea how I can achieve 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
You can use set intersection operations with your
ArrayList
objects.Something like this:
Now,
l3
should have only common elements betweenl1
andl2
.Using Java 8's
Stream.filter()
method in combination withList.contains()
:Output [1, 5]
In case you want to do it yourself..