下一站1

导航

map获取数字与int比较


已知
  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

posted on 2018-12-09 20:23  下一站1  阅读(1797)  评论(0编辑  收藏  举报