Jun 11

You can tell the parseInt() method what base number system is used by the String that is being parsed.


String hex = "01001101";
int n = Integer.parseInt(hex, 2);

written by objects \\ tags: , , , , ,

Sep 05

se static method java.lang.Integer.valueOf(), or create java.lang.Integer instance directly using constructor.

String s = "123";
try
{
   Integer i = Integer.valueOf(s);

   // or alternatively, create instance directly

   Integer i2 = new Integer(s);
}
catch (java.lang.NumberFormatException ex)
{
   // s is not an integer
}

written by objects \\ tags: , ,