最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實(shí)現(xiàn)字符串和數(shù)字轉(zhuǎn)換工具

 更新時(shí)間:2019年04月23日 08:38:35   作者:我的半畝田  
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)字符串和數(shù)字轉(zhuǎn)換工具,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java字符串和數(shù)字轉(zhuǎn)換工具的具體代碼,供大家參考,具體內(nèi)容如下

package com.test.util;

/**
 * 數(shù)字工具類
 */
public class NumberUtil {

 /**
  * 數(shù)字轉(zhuǎn)換為字符串
  * @param num 數(shù)字
  * @return 字符串,如果 num 為空, 返回空字符串
  */
 public static String num2Str(Object num) {
  String str = null;

  if (num == null) {
   str = "";
  }
  else {
   str = String.valueOf(num);
  }
  return str;
 }

 /**
  * 字符串轉(zhuǎn)換為Integer
  * @param str 字符串
  * @return Integer, str為null時(shí)返回0
  */
 public static Integer getInteger(Object obj) {
  return getInteger(obj, 0);
 }

 /**
  * 字符串轉(zhuǎn)換為Integer
  * @param str 字符串
  * @param def 默認(rèn)值
  * @return Integer, 字符串為null時(shí)返回def
  */
 public static Integer getInteger(Object obj, int def) {
  String str = obj == null ? "" : obj.toString();

  Integer i = null;

  if (str.trim().length() == 0) {
   i = new Integer(def);
  }
  else {
   try {
    i = Integer.valueOf(str);
   }
   catch (Exception e) {
   }
  }

  return i == null ? new Integer(def) : i;
 }

 /**
  * 字符串轉(zhuǎn)換為Long
  * @param str 字符串
  * @return Long, str為null時(shí)返回0
  */
 public static Long getLong(Object obj) {
  return getLong(obj, 0);
 }

 /**
  * 字符串轉(zhuǎn)換為Long
  * @param str 字符串
  * @param def 默認(rèn)值
  * @return Long, 字符串為null時(shí)返回def
  */
 public static Long getLong(Object obj, long def) {
  String str = obj == null ? "" : obj.toString();

  Long l = null;

  if (str.trim().length() == 0) {
   l = new Long(def);
  }
  else {
   try {
    l = Long.valueOf(str);
   }
   catch (Exception e) {
   }
  }

  return l == null ? new Long(def) : l;
 }

 /**
  * 字符串轉(zhuǎn)換為Integer
  * @param str 字符串
  * @return Integer, str為null時(shí)返回0
  */
 public static int getIntegerValue(Object obj) {
  return getIntegerValue(obj, 0);
 }

 /**
  * 字符串轉(zhuǎn)換為Integer
  * @param str 字符串
  * @param def 默認(rèn)值
  * @return Integer, 字符串為null時(shí)返回def
  */
 public static int getIntegerValue(Object obj, int def) {
  return getInteger(obj, def).intValue();
 }

 /**
  * 字符串轉(zhuǎn)換為Long
  * @param str 字符串
  * @return Long, str為null時(shí)返回0
  */
 public static long getLongValue(Object obj) {
  return getLongValue(obj, 0);
 }

 /**
  * 字符串轉(zhuǎn)換為Long
  * @param str 字符串
  * @param def 默認(rèn)值
  * @return Long, 字符串為null時(shí)返回def
  */
 public static long getLongValue(Object obj, long def) {
  return getLong(obj, def).longValue();
 }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

平和县| 尖扎县| 共和县| 贵南县| 屏山县| 云阳县| 都安| 苏尼特左旗| 中西区| 错那县| 新化县| 鸡泽县| 灵山县| 景宁| 福泉市| 星子县| 涞水县| 滨州市| 易门县| 辉南县| 龙口市| 沧源| 鄱阳县| 鄯善县| 金乡县| 贞丰县| 永济市| 杭州市| 阳江市| 中江县| 上林县| 平昌县| 会泽县| 名山县| 英德市| 崇州市| 张家界市| 瑞丽市| 凤山市| 新绛县| 太保市|