Java's valueOf () method

valueOf () method returns the given parameters Number native object value, the parameter may be a native data types, String like.

This method is static. The method may receive two parameters is a string, it is a base.

 

grammar

This method has the following syntax:

static Integer valueOf(int i) static Integer valueOf(String s) static Integer valueOf(String s, int radix)

parameter

  • i - Integer Integer object.

  • s - Integer String object.

  • radix - used in parsing a string s base, to specify the hexadecimal number.

return value

  • Integer valueOf (int i): Returns a specified instance int Integer value.

  • Integer valueOf (String s): Returns Integer String object values ​​stored specified.

  • Integer valueOf (String s, int radix): Returns an Integer object stored in the base by the second argument when the value provided by the parsed from the specified String extracted.

Examples

public class Test{ public static void main(String args[]){         Integer x =Integer.valueOf(9);         Double c = Double.valueOf(5);         Float a = Float.valueOf("80");         Integer b = Integer.valueOf("444",16); // 使用 16 进制         System.out.println(x);         System.out.println(c);         System.out.println(a);         System.out.println(b);     } }

Compile the above program, the output is:

9
5.0
80.0 1092

Guess you like

Origin www.cnblogs.com/022414ls/p/11583381.html