public static void main(String[] args) {
Long a = 44l;
Long b=null;
HashMap<String, Object> map = new HashMap<>();
map.put("lirui",a);
map.put("lizhi",b);
Object lirui = map.get("lirui");
//String haha = (String)lirui;//报错 java.lang.Long cannot be cast to java.lang.String
if (lirui!=null){
Long c = Long.valueOf(String.valueOf(lirui));
System.out.println(c);
}
Object lizhi = map.get("lizhi");
Long d = null;
if (lizhi!=null){
d = Long.valueOf(String.valueOf(lirui));
System.out.println(d);
}
}
java中的常用数据结构及类型转换
最新推荐文章于 2024-02-18 11:48:06 发布