This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Integer" Watch "Integer" New topic
Author

Integer

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);
System.out.println(i);

}

}
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
jQuery in Action, 2nd edition
 
subject: Integer
 
Similar Threads
Wrapper Class
Var args question...
Unable to deploy an EJB.
Exception:Attempt to get a lock for a null object ?
wrapper class