(String) | String.valueOf()

Map m = new HashMap();
Integer i = 5;
String s = null;
m.put("val1", i);
m.put("val2", s);

System.err.println(m.get("val1"));
System.err.println(String.valueOf(m.get("val1")));
System.err.println((String)m.get("val1"));    //java.lang.Integer cannot be cast to java.lang.String

System.err.println(m.get("val2"));
System.err.println(String.valueOf(m.get("val2")));
System.err.println((String)m.get("val2"));

posted @ 2014-11-01 15:22  七郎  Views(352)  Comments(0Edit  收藏  举报