collections - Java HashSet remove(e) method doesn't behave as I expected -


I am unable to understand the logic behind this.

Case 1:

  Hashसेट Shortset = New Hashet (); For (abbreviate i = 0; i   

OP: Size: 3 cmsets: [0, 1, 2]

Case 2:

 < Code> Hashless Shortset = New Hashet (); For (int i = 0; i   

Op: Size: 1 comma: [2]

I want to understand the main reason behind this, why do it The output is different from what is behind the scenario by changing from short to int . The problem is that in the first case, expression i

i - 1 type int those values ​​are respectively small and integer Boxing on - the integer is not set, so it can not be removed.

You can fix this with an artist:

 for  (abbreviate i = 0; i   

In your second case, both i and i - 1 type of int (Then boxed on integer ), so the entries you are adding can also be deleted ...

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

c# - passing input text from view to contoller with FacebookContext using Facebook app -

Calling a C++ function from C# by passing a string with variable size to it -