Example usage for java.lang Integer valueOf

List of usage examples for java.lang Integer valueOf

Introduction

In this page you can find the example usage for java.lang Integer valueOf.

Prototype

public static Integer valueOf(String s, int radix) throws NumberFormatException 

Source Link

Document

Returns an Integer object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println(Integer.valueOf("100", 2));
    System.out.println(Integer.valueOf("100", 8));
    System.out.println(Integer.valueOf("100", 10));
    System.out.println(Integer.valueOf("100", 16));
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    int i = Integer.valueOf("1234A", 16).intValue();
    // or/* w  w  w. j  a  v  a2  s. c  o m*/
    i = Integer.parseInt("BBA", 16);
}

From source file:Main.java

public static void main(String[] args) {
    String str = "01111111";
    int radix = 2;

    // Creates an Integer object from the string
    Integer intObject = Integer.valueOf(str, radix);

    // Extracts the int value from the string
    int intValue = Integer.parseInt(str, 2);

    System.out.println("str = " + str);
    System.out.println("intObject = " + intObject);
    System.out.println("intValue = " + intValue);

}

From source file:Main.java

public static byte intToByte(int i) {
    return Integer.valueOf(Integer.toHexString(i), 16).byteValue();
}

From source file:Main.java

public static Integer getNetworkFromInteger(Integer addr) {
    return Integer.valueOf(Integer.toHexString(addr).substring(0, 1), 16);
}

From source file:Main.java

public static Integer[] getColorRGB(String hex) {

    return new Integer[] { Integer.valueOf(hex.substring(0, 2), 16), Integer.valueOf(hex.substring(2, 4), 16),
            Integer.valueOf(hex.substring(4, 6), 16) };
}

From source file:Main.java

public static Color hex2Rgb(String colorStr) {
    return new Color(Integer.valueOf(colorStr.substring(1, 3), 16),
            Integer.valueOf(colorStr.substring(3, 5), 16), Integer.valueOf(colorStr.substring(5, 7), 16));
}

From source file:Main.java

public static int hexStringToOctalString(String hexString) {
    int result = 0;
    try {// w w w .ja v  a  2 s . c om
        result = Integer.valueOf(hexString, 16);
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

public static String octalStringToDecimalString(String octal) {
    String decimal = "0";
    try {//from   w  w  w. j  a v  a 2 s  . com
        decimal = Integer.valueOf(octal, 8).toString();
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return decimal;
}

From source file:Main.java

public static String binaryStringToDecimalString(String octal) {
    String decimal = "0";
    try {/*from  www .  j av  a  2s .  c o  m*/
        decimal = Integer.valueOf(octal, 2).toString();
    } catch (NumberFormatException e) {
        e.printStackTrace();
    }
    return decimal;
}