• Post Reply Bookmark Topic Watch Topic
  • New Topic

Integer  RSS feed

 
Aruna Balasuriya
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why this code fail at runtime

public class Test{



public static void main(String[] args) {
Integer i = Integer.parseInt("0xF",16);
System.out.println(i);

}

}
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "0x" prefix is used by the compiler to inform the compiler to parse the following token as a hexidecimal string.

It is not needed, nor supported, by the Integer parseInt() method, as the radix is passed as a parameter.

Henry
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!