java 将 object转成Integer

/**
 * 将object转为Integer类型
 * @param object
 * @return
 */
public static Integer getIntegerByObject(Object object){
   Integer in = null;
   
   if(object!=null){
      if(object instanceof Integer){
         in = (Integer)object;
      }else if(object instanceof String){
         in = Integer.parseInt((String)object);
      }else if(object instanceof Double){
         in = (int)((double)object);
      }else if(object instanceof Float){
         in = (int)((float)object);
      }else if(object instanceof BigDecimal){
         in = ((BigDecimal)object).intValue();
      }else if(object instanceof Long){
         in = ((Long)object).intValue();
      }
   }
   
   return in;
}
发布了60 篇原创文章 · 获赞 6 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/xiaoluo5238/article/details/81975089