Example
Return a string representation of different data types:
java
char[] myArray = {'a', 'b', 'c'};
System.out.println(String.valueOf(myArray));
System.out.println(String.valueOf('A'));
System.out.println(String.valueOf(true));
System.out.println(String.valueOf(4.5f));
System.out.println(String.valueOf(5.2));
System.out.println(String.valueOf(12));
System.out.println(String.valueOf(1400L));
Definition and Usage
The valueOf() method returns the string representation of the specified value.
Syntax
One of the following:
java
public static String valueOf(boolean data)
java
public static String valueOf(char data)
java
public static String valueOf(char[] data)
java
public static String valueOf(char[] data, int start, int length)
java
public static String valueOf(double data)
java
public static String valueOf(float data)
java
public static String valueOf(int data)
java
public static String valueOf(long data)
java
public static String valueOf(Object data)
Parameter Values
| Parameter | Description |
|---|---|
| data | Required. The data to be represented as a string. |
| start | Optional. If a char array is provided, a subset of the array can be represented. This argument specifies where the subset starts. |
| length | Optional. If a char array is provided, a subset of the array can be represented. This argument specifies the length of the subset. |
Technical Details
| Returns: | A String representation of the argument. |
|---|---|
| Throws: | IndexOutOfBoundsException - If start or length are negative or start + length is greater than the length of the array. |
| Java version: | Any |