What is "Integer.valueOf (). Assuming intValue ()"?

Here is a line of java code that I did not understand.

 String line = "Some data";//I understand this line
 int size;//I understand this line too

 size = Integer.valueOf(line,16).intValue();//Don't understand this one

I know that Integer.ValueOf (string ) is the same as Integer.parseInt (string) , right? Correct me if I am wrong; Thank.

+5
source share
4 answers

Integer.ValueOf(line,16)converts a string value lineto an object Integer. In this case, the radius is 16.

intValue()gets the value intfrom the one created above Integer object.

In addition, the above two steps are equivalent Integer.parseInt(line,16).

For more information, see the Java Integer API documentation .

+6
source

, :

size = Integer.parseInt(line, 16);

, , :

size = Integer.valueOf(Integer.parseInt(line, 16)).intValue();

.

-1 , , . , , Integer.parseInt, size , Integer.valueof, .

+4

.

public class Test {
    public static void main(String[] args) {
        String s = "CAFE";
        Integer m = Integer.valueOf(s, 16);
        int n = m.intValue();

        System.out.println(n);
    }
}

Integer - , int, .

0
" = Integer.valueOf().intValue()"

:

String myNumber = "54";    
int c = Integer.valueOf(myNumber).intValue();  // convert strings to numbers

:

54 // like int (and before was a String)
-1

All Articles