Without constructing an instance of class Integer, the argument is an int and a method of Vector can handle it directly without autoboxing. The compiler use the easiest way as detailed in Java Language Specification.
This version removes the second Integer (index = 1) because it's explicitly an Integer:
import java.util.Vector;
public class VectorAutoBox {
public static void main(String[] args) {
Vector vector = new Vector();
vector.add(1);
vector.add(5);
vector.add(2);
vector.add(3);
vector.add(4);
vector.add(6);
System.out.println(vector);
vector.remove( new Integer( 5 )); // case 1
// vector.remove( 5 ); // case 2
System.out.println(vector);
}
}
Outputs for case 1:
[1, 5, 2, 3, 4, 6]
[1, 2, 3, 4, 6] value '5' at index 1 removed
Outputs for case 2:
[1, 5, 2, 3, 4, 6]
[1, 5, 2, 3, 4] value '6' at index 5 removed