Example usage for java.lang Integer parseInt

List of usage examples for java.lang Integer parseInt

Introduction

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

Prototype

public static int parseInt(String s, int radix) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed integer in the radix specified by the second argument.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println(Integer.toHexString(1976));

    System.out.println(Integer.parseInt("7b8", 16));
}

From source file:Main.java

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

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

From source file:Main.java

public static void main(String[] args) {
    int integer = 127;
    String binary = Integer.toBinaryString(integer);
    System.out.println("Binary value of " + integer + " is " + binary + ".");

    int original = Integer.parseInt(binary, 2);
    System.out.println("Integer value of binary '" + binary + "' is " + original + ".");
}

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 void main(String[] args) {
    int integer = 1024;

    String octal = Integer.toOctalString(integer);

    System.out.printf("Octal value of %d is '%s'.\n", integer, octal);
    System.out.printf("Octal value of %1$d is '%1$o'.\n", integer);

    int original = Integer.parseInt(octal, 8);
    System.out.printf("Integer value of octal '%s' is %d.", octal, original);
}

From source file:Main.java

public static void main(String args[]) {
    Boolean b1 = new Boolean("TRUE");
    Boolean b2 = new Boolean("FALSE");
    System.out.println(b1.toString() + " or " + b2.toString());
    for (int j = 0; j < 16; ++j)
        System.out.print(Character.forDigit(j, 16));

    Integer i = new Integer(Integer.parseInt("ef", 16));
    Long l = new Long(Long.parseLong("abcd", 16));
    long m = l.longValue() * i.longValue();
    System.out.println(Long.toString(m, 8));

}

From source file:Main.java

public static void main(String args[]) {
    Boolean b1 = new Boolean("TRUE");
    Boolean b2 = new Boolean("FALSE");
    System.out.println(b1.toString() + " or " + b2.toString());
    for (int j = 0; j < 16; ++j)
        System.out.print(Character.forDigit(j, 16));

    Integer i = new Integer(Integer.parseInt("ef", 16));
    Long l = new Long(Long.parseLong("abcd", 16));
    long m = l.longValue() * i.longValue();
    System.out.println(Long.toString(m, 8));
    System.out.println(Float.MIN_VALUE);
    System.out.println(Double.MAX_VALUE);
}

From source file:WrappedClassApp.java

public static void main(String args[]) {
    Boolean b1 = new Boolean("TRUE");
    Boolean b2 = new Boolean("FALSE");
    System.out.println(b1.toString() + " or " + b2.toString());
    for (int j = 0; j < 16; ++j)
        System.out.print(Character.forDigit(j, 16));
    System.out.println();/*from ww w  .j  a v a  2 s  .co  m*/
    Integer i = new Integer(Integer.parseInt("ef", 16));
    Long l = new Long(Long.parseLong("abcd", 16));
    long m = l.longValue() * i.longValue();
    System.out.println(Long.toString(m, 8));
    System.out.println(Float.MIN_VALUE);
    System.out.println(Double.MAX_VALUE);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader("ravi.txt"));
    while (true) {
        String line = br.readLine();
        if (line == null)
            break;
        if (!UCODE_PATTERN.matcher(line).matches()) {
            System.err.println("Bad input: " + line);
        } else {/*w  w w  . j a  va2 s  .  c om*/
            String hex = line.substring(2, 6);
            int number = Integer.parseInt(hex, 16);
            System.out.println(hex + " -> " + ((char) number));
        }
    }
}

From source file:org.n52.iceland.statistics.api.utils.KibanaExporter.java

public static void main(String args[]) throws Exception {
    if (args.length != 2) {
        System.out.printf("Usage: java KibanaExporter.jar %s %s\n", "localhost:9300", "my-cluster-name");
        System.exit(0);// w  w w.j  a  v a  2  s . c o m
    }
    if (!args[0].contains(":")) {
        throw new IllegalArgumentException(
                String.format("%s not a valid format. Expected <hostname>:<port>.", args[0]));
    }

    // set ES address
    String split[] = args[0].split(":");
    InetSocketTransportAddress address = new InetSocketTransportAddress(InetAddress.getByName(split[0]),
            Integer.parseInt(split[1], 10));

    // set cluster name
    Builder tcSettings = Settings.settingsBuilder();
    tcSettings.put("cluster.name", args[1]);
    System.out.println("Connection to " + args[1]);

    client = TransportClient.builder().settings(tcSettings).build();
    client.addTransportAddress(address);

    // search index pattern for needle
    searchIndexPattern();

    KibanaConfigHolderDto holder = new KibanaConfigHolderDto();
    System.out.println("Reading .kibana index");

    SearchResponse resp = client.prepareSearch(".kibana").setSize(1000).get();
    Arrays.asList(resp.getHits().getHits()).stream().map(KibanaExporter::parseSearchHit).forEach(holder::add);
    System.out.println("Reading finished");

    ObjectMapper mapper = new ObjectMapper();
    // we love pretty things
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    File f = new File("kibana_config.json");

    try (FileOutputStream out = new FileOutputStream(f, false)) {
        mapper.writeValue(out, holder);
    }

    System.out.println("File outputted to: " + f.getAbsolutePath());

    client.close();

}