Latest web development tutorials

Java valueOf () method

Java String class Java String class


There are several different forms valueOf () method:

  • valueOf (boolean b): Returns a string representation of the boolean argument..

  • valueOf (char c): Returns a string representation of the char argument.

  • valueOf (char [] data): Returns a string representation of the char array argument form.

  • valueOf (char [] data, int offset, int count): String Returns the char array argument of a particular sub-array representation.

  • valueOf (double d): Returns a string representation of the double argument.

  • valueOf (float f): Returns a string representation of the float argument.

  • valueOf (int i): int Returns a string representation of the argument.

  • valueOf (long l): Returns a string representation of the long argument.

  • valueOf (Object obj): Returns a string representation of the Object argument.

grammar

static String valueOf(boolean b) 

或 

static String valueOf(char c) 

或

static String valueOf(char[] data) 

或

static String valueOf(char[] data, int offset, int count) 

或

static String valueOf(double d) 

或

static String valueOf(float f) 

或

static String valueOf(int i)

或

static String valueOf(long l)

或

static String valueOf(Object obj) 

parameter

  • Specify the type parameter.

return value

Whitespace string head and tail removed.

Examples

public class Test {
    public static void main(String args[]) {
    	double d = 1100.00;
        boolean b = true;
        long l = 1234567890;
        char[] arr = {'r', 'u', 'n', 'o', 'o', 'b' };

        System.out.println("返回值 : " + String.valueOf(d) );
        System.out.println("返回值 : " + String.valueOf(b) );
        System.out.println("返回值 : " + String.valueOf(l) );
        System.out.println("返回值 : " + String.valueOf(arr) );
	}
}

The above program execution results:

返回值 : 1100.0
返回值 : true
返回值 : 1234567890
返回值 : w3big

Java String class Java String class