for (String a: args) if(!uniques.add(a)) dups.add(a) | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Resposta
+ 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