Is there any possibility that Integer.toString(args)
give an NullPointerException
like String.valueOf(args)
.
I know its Silly Question but I want to be clear that is there any possibility that Integer.toString()
can give NullPointerException
.
Technically yes, due to unboxing. Although I'm not sure if that is what you meant:
public class Test {
public static void main(String[] args) {
Integer i = null;
System.out.println(Integer.toString(i)); // NullPointerException
}
}
Integer.toString(args)
may give an NullPointerException
unlike String.valueOf(args)
.
Integer i = null;
Integer.toString(i); // Null pointer exception!!
String.valueOf(i); // No exception
i.toString(); // Again, Null pointer exception!!
See my experiment here : http://rextester.com/YRGGY86170
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With