for (String a: args) if(!uniques.add(a)) dups.add(a) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

for (String a: args) if(!uniques.add(a)) dups.add(a)

uniques and dups are objects of set interface. plz someone explain how second line of code works ?

6th Oct 2016, 2:37 PM
ujjwalkarn30
ujjwalkarn30 - avatar
1 Answer
+ 1
A set contains unique values. The add-method adds a value to the set. If this set already contains the element, the call leaves the set unchanged and returns false. So in the set unique (just a name :-) ) are the unique values of args. The set dups contains the duplicates.
2nd Jan 2019, 9:16 PM
PapaBT
PapaBT - avatar