Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

valueOf()

Example

Provide a string representation of various data types.

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 furnishes the string representation of the specified value.

Syntax

One of the following:

public static String valueOf(boolean data)
public static String valueOf(char data)
public static String valueOf(char[] data)
public static String valueOf(char[] data, int start, int length)
public static String valueOf(double data)
public static String valueOf(float data)
public static String valueOf(int data)
public static String valueOf(long data)
public static String valueOf(long data)

Parameter Values

Parameter

Description

data

Necessary. The data to be depicted as a string.

start

Optional. If a char array is supplied, a portion of the array can be depicted. This parameter indicates the starting point of the subset.

length

Optional. In case a char array is given, a segment of the array can be illustrated. This parameter denotes the length of that segment.

Technical Details

Returns

A representation of the argument as a string.

Throws

IndexOutOfBoundsException occurs if either start or length is negative, or if the sum of start and length exceeds the length of the array.

Java Version

Any