for (String a: args) if(!uniques.add(a)) dups.add(a) | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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 ответ
+ 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