Integer.valueOf(String s);//采用了亨元设计模式: 亨元模式: 它是以一种“节约内存,提高性能”为出发点的设计模式,运用共享技术有效的支持大量细粒度对象的复用. 源码解析: private static class IntegerCache { static final int low = -128; static final int high; static final Integer cache[]; //类加载时提前先把-127到128 static { // h
通过查看java.lang.Integer的源码可以发现, 它们最终调用的都是 /** * Parses the string argument as a signed integer in the radix * specified by the second argument. The characters in the string * must all be digits of the specified radix (as determined by * whether {@link
先看一下下面的结果 1.System.out.println(127==127); //true , int type compare 2.System.out.println(128==128); //true , int type compare 3.System.out.println(new Integer(127) == new Integer(127)); //false, object compare 4.System.out.println(Integer.parseInt("1
1.Integer.parseInt(): public static int parseInt(String s) throws NumberFormatException { return parseInt(s,10); } public static int parseInt(String s, int radix) throws NumberFormatException{ /* * WARNING: This method may be invoked early during VM