(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"));

上一篇:(String)、toString、String.valueOf的区别


下一篇:String、String.valueOf、toString 它们三者的区别总结