Java Byte Create toByte(Object value)

Here you can find the source of toByte(Object value)

Description

Convert an Object to a Byte.

License

Apache License

Declaration

public static Byte toByte(Object value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from  w w w . j a v  a 2  s .  co m*/
     * Convert an Object to a Byte.
     */
    public static Byte toByte(Object value) {
        if (value == null)
            return null;
        if (value instanceof Byte)
            return (Byte) value;
        if (value instanceof String) {
            if ("".equals((String) value))
                return null;
            return new Byte((String) value);
        }
        if (value instanceof Number)
            return new Byte(((Number) value).byteValue());

        return new Byte(value.toString());
    }

    /**
     * Convert an Object to a byte, or 0 if it is null.
     */
    public static byte byteValue(Object value) {
        if (value == null)
            return 0;
        return toByte(value).byteValue();
    }
}

Related

  1. toByte(Object obj)
  2. toByte(Object obj)
  3. toByte(Object obj)
  4. toByte(Object obj)
  5. toByte(Object value)
  6. toByte(Object value)
  7. toByte(short unsignedByte)
  8. toByte(short value, boolean first)
  9. toByte(String hex)