Java Byte Create toByte(Object ob, Byte defaultByte)

Here you can find the source of toByte(Object ob, Byte defaultByte)

Description

to Byte

License

Open Source License

Declaration

public static Byte toByte(Object ob, Byte defaultByte) 

Method Source Code

//package com.java2s;

public class Main {

    public static Byte toByte(Object ob, Byte defaultByte) {

        if (ob == null) {
            return defaultByte;
        }//  ww  w.  ja  v a 2s. c  o m

        if (ob instanceof Integer) {
            return ((Integer) ob).byteValue();
        } else if (ob instanceof Float) {
            return ((Float) ob).byteValue();
        } else if (ob instanceof Double) {
            return ((Double) ob).byteValue();
        } else if (ob instanceof Byte) {
            return ((Byte) ob).byteValue();
        } else {
            try {
                return new Byte(ob.toString());
            } catch (Exception e) {
                return defaultByte;
            }
        }
    }

    public static Byte toByte(Object ob) {
        return toByte(ob, (byte) 0);
    }
}

Related

  1. toByte(int rgb)
  2. toByte(long l)
  3. toByte(long l, byte[] b, int off, boolean bigEndian)
  4. toByte(Number num)
  5. toByte(Object o)
  6. toByte(Object obj)
  7. toByte(Object obj)
  8. toByte(Object obj)
  9. toByte(Object obj)