1. 程式人生 > >map獲取數字與int比較

map獲取數字與int比較

parseint map eof bject 使用 轉換 exceptio als decimal


已知
  map.get("id")為數字,如:123
問題
  id.equals(123)

   結果為false
而使用
  int id = (Integer)map.get("id");
則會報異常(類型轉換異常)
  java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer
解決
  Object id1 = map.get("id");
  int id = Integer.parseInt(String.valueOf(id1));
結果則為true

map獲取數字與int比較