Here is the problem description:
in my preparation for ocjp test, I have encountered a problem, and I can not figure out what's wrong with it.
package test;
class Test005{
public static void main(String[] args){
//Integer i = args[0];//cannot convert string to Integer
Integer I = Integer.valueOf(args[0]); // Error ArrayOutOfBoundsException :0
int j = 12;
System.out.println(j == i);
}
}
the first Integer I = args[0]
is wrong, because the args[0]
is a string, while the I is a int
; however, the second Ineteger I = Integer.valueOf(args[0])
complies smoothly, but the JVM throw an error, and I just cannot figure it why?