Easy Tutorial
❮ Data Intopost Arrays Equal ❯

Java valueOf() Method

Java String Class


The valueOf() method has several different forms:

-

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

-

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

-

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

-

valueOf(char[] data, int offset, int count): Returns the string representation of a specific subarray of the char array argument.

-

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

-

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

-

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

-

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

-

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

Syntax

static String valueOf(boolean b)

or

static String valueOf(char c)

or

static String valueOf(char[] data)

or

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

or

static String valueOf(double d)

or

static String valueOf(float f)

or

static String valueOf(int i)

or

static String valueOf(long l)

or

static String valueOf(Object obj)

Parameters

-

Specifies the type of argument.

Return Value

Returns the string representation of the argument type.

Example

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("Return Value : " + String.valueOf(d) );
        System.out.println("Return Value : " + String.valueOf(b) );
        System.out.println("Return Value : " + String.valueOf(l) );
        System.out.println("Return Value : " + String.valueOf(arr) );
    }
}

The above program execution result is:

Return Value : 1100.0
Return Value : true
Return Value : 1234567890
Return Value : runoob

Java String Class

❮ Data Intopost Arrays Equal ❯