I am trying to get common numbers from two lists and getting UnsupportedOperationException. Below is my code. Please suggests your thoughts?
Requirement: I want all common numbers from two lists as output. I am able to get unique numbers by using set but that does not fulfill the requirement.
Output:
[1, 3, 5]
Exception in
thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(Unknown Source)
at java.util.AbstractList$Itr.remove(Unknown Source)
at java.util.AbstractCollection.retainAll(Unknown Source)
at com.test.ArrayListTEest.main(ArrayListTEest.java:20)