About Question enthuware.ocpjp.v11.2.3308 :
Posted: Thu Apr 29, 2021 4:50 am
This question have a bug
enum SIZE
{
TALL, JUMBO, GRANDE;
}
class CoffeeMug
{
public static void main(String[] args)
{
var hs = new HashSet<SIZE>();
hs.add(SIZE.TALL); hs.add(SIZE.JUMBO); hs.add(SIZE.GRANDE);
hs.add(SIZE.TALL); hs.add(SIZE.TALL); hs.add(SIZE.JUMBO);
for(SIZE s : hs) System.out.print(s+" ");
}
}
This is set, should print all elements without duplicate.
Simulator give me a "right" answer that it should print this set with duplicate items.
I checked this code in compiler.
Compiler return me that it sholud print only not duplicate items.
Please fix
enum SIZE
{
TALL, JUMBO, GRANDE;
}
class CoffeeMug
{
public static void main(String[] args)
{
var hs = new HashSet<SIZE>();
hs.add(SIZE.TALL); hs.add(SIZE.JUMBO); hs.add(SIZE.GRANDE);
hs.add(SIZE.TALL); hs.add(SIZE.TALL); hs.add(SIZE.JUMBO);
for(SIZE s : hs) System.out.print(s+" ");
}
}
This is set, should print all elements without duplicate.
Simulator give me a "right" answer that it should print this set with duplicate items.
I checked this code in compiler.
Compiler return me that it sholud print only not duplicate items.
Please fix