Hi,
I am preparing for
SCJP 1.4. Sunday is my exam!
I came across following question on collection addAll method:
What is the result of executing the following fragment of code:
The answer to above question is d. Which indicates that addAll does not adds a value if that is already present in collection.
Is this correct understanding? Shouldn't this be behavior of only Set collection? What all collection addAll method behaves in similar way?
Now here is bigger problem in my head:
if I replace line //3 addAdd above with following two lines:
s2.add("a");// 1
s1.addAll(2, s2);// 2
then the output of program is:
[a, b, a, c]
now here addAll is adding same element !!
I am confused, please help!
TIA!