Java's Integer.valueOf and Integer.parseInt

com.wu Package; 

/ ** 
 distinction * Inteegr.valueOf () and the Integer.parseInt () method 
 * 
 * / 
public class the App 
{ 
    / ** 
     * returns a valueOf Integer (integer) the object, when the character is processed string -128 and 127 (inclusive) is between, returned objects are cached in advance. 
     * calls the second row returns false because 128 is not cached, so that each call will generate a new integer Object so that both the integer 128 objects are different objects 
     * is important for you to know that in the above comparison, you compare the actual return is the object integer.valueOf references, so when you compare objects outside of integer cached equal judgment does not return true, even if you pass a valueOf value is equal to useless 
     * parseInt () is not an integer object returned, but a basic element of type int 
     * this is why the last judgment will return true , the third row is determined, at the time of determination equal, the comparison is actually == 128 128, it must be equal to 
     * @param args 
     * / 
    public static void main (String [] args) 
    { 
        / ** 
         * to true 
         * false 
         * true
         */
        System.out.println(Integer.valueOf("127")==Integer.valueOf("127"));
        System.out.println(Integer.valueOf("128")==Integer.valueOf("128"));
        System.out.println(Integer.parseInt("128")==Integer.valueOf("128"));
    }
}

  

 

Guess you like

Origin www.cnblogs.com/wylwyl/p/10962950.html