Java Integer Create toIntValue(char ch)

Here you can find the source of toIntValue(char ch)

Description

to Int Value

License

Open Source License

Declaration

public static int toIntValue(char ch) 

Method Source Code

//package com.java2s;

public class Main {
    public static int toIntValue(char ch) {
        if (!isDigit(ch)) {
            throw new IllegalArgumentException("The character " + ch + " is not in the range '0' - '9'");
        }/*from w  w w . j av a2s.c o  m*/
        return ch - 48;
    }

    public static int toIntValue(char ch, int defaultValue) {
        if (!isDigit(ch)) {
            return defaultValue;
        }
        return ch - 48;
    }

    public static int toIntValue(Character ch) {
        if (ch == null) {
            throw new IllegalArgumentException("The character must not be null");
        }
        return toIntValue(ch.charValue());
    }

    public static int toIntValue(Character ch, int defaultValue) {
        if (ch == null) {
            return defaultValue;
        }
        return toIntValue(ch.charValue(), defaultValue);
    }

    public static boolean isDigit(char c) {
        return (c >= '0') && (c <= '9');
    }
}

Related

  1. toIntsFromUBytes(byte[] byteArray)
  2. toIntStr(String floatStr)
  3. toIntString(Integer integer)
  4. toIntString(Object object)
  5. toIntUnsigned(short x)
  6. toIntValue(char ch, int defaultValue)
  7. toIntValue(final char ch)
  8. toIntValue(final Object o)
  9. toIntValue(Object number)