Java中 intValue,parseInt,Valueof

 
 

intValue()

1.intValue () method of class java.lang.Number, Number is a an abstract class. All values ​​in Java classes inherit it. In other words, not only is there intValue method Integer, Double, Long and others have this method. 

 

valueOf()

 

String category has been provided to convert the data patterns into the basic static method of String , i.e.  String.valueOf ()  This method for multiple carrier parameter 

 

There are several

 

(. 1) String.valueOf (boolean b)  : The boolean variable b is converted into a string 
(2) String.valueOf (char c)  : the char is converted into a string variable c 
(. 3) String.valueOf (char [] Data)  : a char data array into a string 
(. 4) String.valueOf (char [] data, int offset, int count)  : the data in the data array char [offset] begins to take count conversion elements into a string 

 

(. 5) String.valueOf (double d)  : The double converted to a string variable d 
(. 6) String.valueOf (float f)  : converts a string float variable f 
(. 7) String.valueOf (I int)  : The int converted to a string variable i 
(. 8) String.valueOf (long l)  : l converts the variable to a long string 
(. 9) String.valueOf (Object obj)  : converts a string object obj equal obj.toString ( ) 

 

  Usage as follows: 
  int I = 10; 
  String str = String.valueOf (I); 
  this would be time str "10" 

 

 Integer. ValueOf () can be converted to the basic package type int type Integer, String or converted into Integer, String Null or if it is "" will be given

 

 

Common methods:

intValue () is the basic parameter Integer object into the data type of int;
int IT = new new Integer () intValue ().;

 

static method:

the parseInt () is the basic data into the String parameter of type int;
int IT = the Integer.parseInt ( "AAA");

valueOf () is the given String / int parameter becomes the underlying data type of Integer;
Integer = Integer.valueOf ITR ( "aaa"); // valueOf () call to the underlying fact is that Integer new new ();
Integer ITR = new Integer ( "aaa");

(JDK version now supports the automatic boxing and unboxing.)

appendix:

Integer a=new Integer(1);
Integer a=Integer.valueOf(1);
Both are to get an Integer object, but Integer.valueOf of high efficiency.
 

Guess you like

Origin www.cnblogs.com/memorjun/p/12272790.html