Java String valueOf() Examples

Java String valueOf() method is used to create the String representation from different types of inputs.

String valueOf() method is overloaded and accept following types of arguments:

  1. int
  2. long
  3. float
  4. double
  5. char
  6. char array
  7. boolean
  8. Object

Java String valueOf() Method Signature

Below image shows the valueOf() overloaded methods, they all are public and static and returns String.


If we pass null argument, then it will throw NullPointerException.

Java String valueOf() Examples

Let’s look at some code snippets for String valueOf() methods usage.

String.valueOf(Object obj)

Output: Data{id:10}

Note that toString() method is used to create the String representation of the Object.

String.valueOf(char[] data)

Output: abc

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

Output: bc

String.valueOf(boolean b)

Output: true

String.valueOf(char c)

Output: A

String.valueOf(int i)

Output: 65

String.valueOf(long l)

Output: 12345

String.valueOf(float f)

Output: 123.45

String.valueOf(double d)

Output: 123.45

That’s all for String valueOf() example.

By admin

Leave a Reply

%d bloggers like this: