Java Short Number Create toShort(Object ob, Short defaultShort)

Here you can find the source of toShort(Object ob, Short defaultShort)

Description

to Short

License

Open Source License

Declaration

public static Short toShort(Object ob, Short defaultShort) 

Method Source Code

//package com.java2s;

public class Main {

    public static Short toShort(Object ob, Short defaultShort) {

        if (ob == null) {
            return defaultShort;
        }//  w ww .j av a2  s  .  c o m

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

    public static Short toShort(Object ob) {
        return toShort(ob, Short.valueOf("0"));
    }
}

Related

  1. toShort(long l)
  2. toShort(long n)
  3. toShort(Number num)
  4. toShort(Number value)
  5. toShort(Object o)
  6. toShort(Object obj)
  7. toShort(Object obj)
  8. toShort(Object obj)
  9. toShort(Object obj)