Convert string to integer

ReturnMethodSummary
static intparseInt(String s)Parses the string argument as a signed decimal integer.
static intparseInt(String s, int radix)Parses the string argument in the radix specified by the second argument.
static IntegervalueOf(int i)Returns a Integer instance representing the specified int value.
static IntegervalueOf(String s)Returns an Integer object holding the value of the specified String.
static IntegervalueOf(String s, int radix)Returns an Integer from String based on the radix.

public class Main {
  public static void main(String[] args) {

    System.out.println(Integer.parseInt("010"));

  }
}

The output:


10

You can also indicate the radix.


public class Main {
  public static void main(String[] args) {

    System.out.println(Integer.parseInt("010",8));

  }
}

The output:


8
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.