Java Integer Create toInt(String value)

Here you can find the source of toInt(String value)

Description

to Int

License

Open Source License

Declaration


public static int toInt(String value) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {

    public static int toInt(String value) {
        if (!isBinary(value))
            return 0;

        if (value.length() > 31)
            return Integer.MAX_VALUE;

        return Integer.parseInt(value, 2);
    }/*  w ww . ja v  a  2s  .c  o m*/

    public static boolean isBinary(String binary) {
        if (binary == null || binary.length() == 0)
            return false;

        for (char c : binary.toCharArray())
            if (!(c == '0' || c == '1'))
                return false;

        return true;
    }
}

Related

  1. toInt(String text, int defaultValue)
  2. toInt(String v, int def)
  3. toInt(String value)
  4. toInt(String value)
  5. toInt(String value)
  6. toInt(String value)
  7. toInt(String value, int _default)
  8. toInt(String value, int def)
  9. toInt(String value, int defaultValue)