I assume you want to map every value in the arr1 array to an int, and the result should be an int[] (not one int). Stream the array, map the elements to an int, and then invoke toArray. Like,

int[] numArr = Arrays.stream(arr1).mapToInt(Integer::valueOf).toArray();

Note that invoking valueOf in this way is still an example of parsing the String to an int.

Answer from Elliott Frisch on Stack Overflow
🌐
Programiz
programiz.com › java-programming › library › string › valueof
Java String valueOf()
System.out.println(String.valueOf(l)); // "-2343834" System.out.println(String.valueOf(f)); // "23.4" System.out.println(String.valueOf(d)); // "923.234" } } In Java, we can convert char and char array to string using the valueOf() method. For example, class Main { public static void main(String[] ...
🌐
Tutorialspoint
tutorialspoint.com › java › java_string_valueof.htm
Java - String valueOf() Method
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) ... See the description. This method returns the string representation. import java.io.*; public class Test { public static void main(String args[]) { double d = 102939939.939; boolean b = true; long l = 1232874; char[] arr = {'a', 'b', 'c', 'd', 'e', 'f','g' }; 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) ); } }
🌐
Tutorialspoint
tutorialspoint.com › java › lang › string_valueof_chararray.htm
Java.lang.String.valueOf(char[] data) Method
package com.tutorialspoint; import java.lang.*; public class StringDemo { public static void main(String[] args) { // character array chararray1 char[] chararr1 = new char[] { 't', 'u', 't', 's' }; String str1 = String.valueOf(chararr1); // character array chararray2 char[] chararr2 = new char[] { '2', '1', '5' }; String str2 = String.valueOf(chararr2); // prints the string representations System.out.println(str1); System.out.println(str2); } }
🌐
Scaler
scaler.com › home › topics › string valueof() in java
String valueOf() in Java - Scaler Topics
April 8, 2024 - It is used to convert any data type, such as int, double, char, or char array, to its string representation by creating a new String object. We can also use valueOf() to convert a char array or a subarray of a char array to a String.
🌐
BeginnersBook
beginnersbook.com › 2017 › 10 › java-string-valueof-method
Java String valueOf() method
June 4, 2024 - char ch = 'Z'; String strChar = String.valueOf(ch); System.out.println(strChar); // Output: "Z" It converts a char array into a String representation.
🌐
W3Schools
w3schools.com › java › ref_string_valueof.asp
Java String valueOf() Method
Arrays Loop Through an Array Real-Life Examples Multidimensional Arrays Code Challenge · Java Methods Java Method Challenge Java Method Parameters
🌐
W3Resource
w3resource.com › java-tutorial › string › string_valueof.php
Java String: valueOf Method - w3resource
August 19, 2022 - The following example shows the ... new char[]{'m','n','o','p'}; // getting the String equivalent of char array data String strVal = String.valueOf(data); // printing the String equivalent of char array System.out.println(strVal); ...
Find elsewhere
🌐
Javatpoint
javatpoint.com › java-string-valueof
Java String valueOf() - Javatpoint
Java Program to capitalize each word in String · Java Main Method · System.out.println() Java Memory Management · Java ClassLoader · Java Heap · Java Decompiler · Java UUID · Java JRE · Java SE · Java EE · Java ME · Java vs. JavaScript · Java vs. Kotlin · Java vs. Python · Java Absolute Value · How to Create File · Delete a File in Java · Open a File in Java · Sort a List in Java · Convert byte Array to String ·
🌐
Codecademy
codecademy.com › docs › java › strings › .valueof()
Java | Strings | .valueOf() | Codecademy
July 26, 2025 - For char[], it converts the entire array to a string. For other array types passed as Object, it calls the array’s toString() method, which typically returns the array’s memory address.
🌐
Tutorial Gateway
tutorialgateway.org › java-string-valueof-method
Java String ValueOf Function
September 11, 2025 - System.out.println("String Representation of Character Array = " + String.valueOf(ch)); The following statement calls the Java valueOf (char[] ch, int Starting_Index, int count) method to return the character array ch string representation. It will start looking for the character at index position 5 (i.e., P) and count seven characters (i.e., P, r, o, g, r, a, m).
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-valueof
Java String valueOf() Method - GeeksforGeeks
December 2, 2024 - Java · public class ValueOf { public static void main(String[] args) { // Character array char[] ch = { 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd' }; String s = String.valueOf(ch, 0, 5); // Convert first 5 characters to string System.out.println("" + s); } } Output ·
Top answer
1 of 11
269

According to the Java documentation, String.valueOf() returns:

if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned.

So there shouldn't really be a difference except for an additional method invocation.

Also, in the case of Object#toString, if the instance is null, a NullPointerException will be thrown, so arguably, it's less safe.

public static void main(String args[]) {  
    String str = null;
    System.out.println(String.valueOf(str));  // This will print a String equal to "null"        
    System.out.println(str.toString()); // This will throw a NullPointerException
} 
2 of 11
27

Differences between String.valueOf(Object) and Object.toString() are:

1) If string is null,

String.valueOf(Object) will return "null", whereas Object::toString() will throw a null pointer exception.

public static void main(String args[]){  
    String str = null;
    
    System.out.println(String.valueOf(str));  // it will print null        
    System.out.println(str.toString()); // it will throw NullPointerException        
}  

2) Signature:

valueOf() method of String class is static. whereas toString() method of String class is non static.

The signature or syntax of string's valueOf() method is given below:

public static String valueOf(boolean b)  
public static String valueOf(char c)  
public static String valueOf(char[] c)  
public static String valueOf(int i)  
public static String valueOf(long l)  
public static String valueOf(float f)  
public static String valueOf(double d)  
public static String valueOf(Object o)

The signature or syntax of string's toString() method is given below:

public String toString()
🌐
Educative
educative.io › answers › how-to-use-stringvalueof-method-in-java
How to use String.valueOf() method in Java
The String.valueOf() method in Java transforms various forms of data into a string representation.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
July 21, 2026 - a String that contains the characters of the character array. public static String valueOf(boolean b) Returns the string representation of the boolean argument. Parameters: b - a boolean. Returns: if the argument is true, a string equal to "true" is returned; otherwise, a string equal to "false" ...
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › String › valueOf
Java String valueOf() - Convert To String | Vultr Docs
December 9, 2024 - The valueOf() method in Java's String class is a static utility function designed to convert various data types into their string representations. This method proves invaluable when you need to transform primitive data types, objects, or arrays ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.string.valueof
String.ValueOf Method (Java.Lang) | Microsoft Learn
Returns the string representation of the char array argument. The contents of the character array are copied; subsequent modification of the character array does not affect the returned string.
🌐
TechVidvan
techvidvan.com › tutorials › java-string-valueof-method
Java String valueOf() Method - TechVidvan
November 11, 2024 - ValueOf() This method returns the string’s primitive value. This technique makes no changes to the original string.