Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes Integer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Integer" Watch "Integer" New topic


Aruna Balasuriya
Ranch Hand

Joined: Nov 14, 2009
Posts: 44
Why this code fail at runtime

public class Test{

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


Henry Wong

Joined: Sep 28, 2004
Posts: 20526

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: Integer
It's not a secret anymore!