Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
Why the answere is 169 not 1996?
(java.util.*is imported) TreeSet set =new TreeSet(); set.add(1); set.add(9); set.add(9); set.add(6); for(Object O : set){ System.out.println(o); } Explain this code?
2 Respostas
+ 2
From java 7 documentation:
"AĀ NavigableSetĀ implementation based on aĀ TreeMap. The elements are ordered using theirĀ natural ordering, or by aĀ ComparatorĀ provided at set creation time, depending on which constructor is used."
TreeSet automaticly sort the given element in ascending order, thats why 6 appear before 9.
Where's the other 9 ?
Also from documentation
"add (E e): Adds the specified element to this set if it is not already present."
+ 6
Only unique values are stored on a set, not duplicate values.