To convert any object to string there are several methods in Java

String convertedToString = String.valueOf(Object);  //method 1

String convertedToString = "" + Object;   //method 2

String convertedToString = Object.toString();  //method 3

I would prefer the first and third

EDIT
If working in kotlin, the official android language

val number: Int = 12345
String convertAndAppendToString = "number = $number"   //method 1

String convertObjectMemberToString = "number = ${Object.number}" //method 2

String convertedToString = Object.toString()  //method 3
Answer from Salmaan on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java string › how to convert an object to string
How to Convert an Object to String | Baeldung
January 5, 2024 - In this tutorial, we’ll explore various techniques for converting an object to its string representation in Java.
🌐
Scaler
scaler.com › home › topics › convert object to string in java
Convert Object to String in Java - Scaler Topics
May 5, 2024 - In Java, you can convert an object to a string using the toString() method, which is a method of the Object class.
🌐
Reddit
reddit.com › r/javahelp › how to convert object to string ?
r/javahelp on Reddit: How to convert object to string ?
October 7, 2020 -

Hello guys, I would like to know the best way to convert object to string with commas separating the year month & day in format (yyyy,mm,dd) . I am trying to do so for the program to place information into a data file. The conversion follows the code line below. I seek your kind assistance and many thanks.

MyDate MyDate = cannedFood.getexpiryDate(); // to convert object MyDate into string

🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-convert-object-to-string
Java Program to Convert Object to String - GeeksforGeeks
July 23, 2025 - The first byte needs to be converted into an object byte which can easily be dealt with to convert to strings. Convert Object to String in java using toString() method of Object class or String.valueOf(object) method. Since there are mainly ...
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › Object › toString
Java Object toString() - Convert To String | Vultr Docs
November 19, 2024 - By default, the toString() method returns a string consisting of the class name followed by "@" and then the hashcode of the object.
Top answer
1 of 12
52

I'm afraid your map contains something other than String objects. If you call toString() on a String object, you obtain the string itself.

What you get [Ljava.lang.String indicates you might have a String array.

2 of 12
14

Might not be so related to the issue above. However if you are looking for a way to serialize Java object as string, this could come in hand

package pt.iol.security;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.codec.binary.Base64;

public class ObjectUtil {

    static final Base64 base64 = new Base64();

    public static String serializeObjectToString(Object object) throws IOException {
        try (
                ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
                GZIPOutputStream gzipOutputStream = new GZIPOutputStream(arrayOutputStream);
                ObjectOutputStream objectOutputStream = new ObjectOutputStream(gzipOutputStream);) {
            objectOutputStream.writeObject(object);
            objectOutputStream.flush();
            return new String(base64.encode(arrayOutputStream.toByteArray()));
        }
    }

    public static Object deserializeObjectFromString(String objectString) throws IOException, ClassNotFoundException {
        try (
                ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(base64.decode(objectString));
                GZIPInputStream gzipInputStream = new GZIPInputStream(arrayInputStream);
                ObjectInputStream objectInputStream = new ObjectInputStream(gzipInputStream)) {
            return objectInputStream.readObject();
        }
    }
}
🌐
Tutorialspoint
tutorialspoint.com › java › lang › object_tostring.htm
Java Object toString() Method
Following is the declaration for java.lang.Object.toString() method ... This method returns a string representation of the object.
Find elsewhere
🌐
Coderanch
coderanch.com › t › 401427 › java › convert-object-string
How do I convert an object into a string? (Beginning Java forum at Coderanch)
But I keep getting an error that the string can not be inserted as the tree is expect an object. Can any one point me in the right direction? ... You're gonna need to explain it a little better or post some code cause from my understanding you have written a method which expects an Object as argument and you are passing in a String (which extends Object), therefore you shouldn't have any problem.
🌐
Princeton
cs.princeton.edu › courses › archive › spr96 › cs333 › java › tutorial › java › strings › conversion.html
Converting Objects to Strings
class ReverseString { public static String reverseIt(String source) { int i, len = source.length(); StringBuffer dest = new StringBuffer(len); for (i = (len - 1); i >= 0; i--) { dest.append(source.charAt(i)); } return dest.toString(); } } It's often convenient or necessary to convert an object to a String because you need to pass it to a method that only accepts String values.
🌐
Delft Stack
delftstack.com › home › howto › java › java convert object to string
How to Convert Object to String in Java | Delft Stack
February 2, 2024 - This example explains how to convert a user-defined object to a string using the toString() method.
🌐
How to do in Java
howtodoinjava.com › home › serialization › serialize object to string in java
Serialize Object to String in Java
July 1, 2024 - In Java, we can serialize an object to String in different ways such as converting to byte[] and thenBase64 encoded string, XML or JSON. Learn with examples.
🌐
CodeGym
codegym.cc › java blog › random › convert object to string in java
Convert Object to String in Java
April 3, 2025 - Another simple way to convert an object to a string in Java is using the string concatenation operator +. When you "add" a string to an object, Java implicitly calls toString() on that object:
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.objects.tostring
Objects.ToString Method (Java.Util) | Microsoft Learn
[<Android.Runtime.Register("toString", "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/String;", "")>] static member ToString : Java.Lang.Object * string -> string
🌐
GeeksforGeeks
geeksforgeeks.org › java › object-tostring-method-in-java
Object toString() Method in Java - GeeksforGeeks
April 4, 2025 - Now we will be dealing with one of its methods, known as the toString() method. We typically do use the toString() method to get the string representation of an object. It is very important and readers should be aware that whenever we try to ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
October 20, 2025 - The class String includes methods ... version specified by the Character class. The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings....
🌐
Java Guides
javaguides.net › 2024 › 01 › convert-object-to-string-in-java.html
How to Convert an Object to a String in Java
June 15, 2024 - For more complex objects, JSON libraries like Gson or Jackson provide a convenient way to convert objects to JSON strings. By understanding these different methods, you can choose the one that best fits your needs and coding style. Happy coding! ... How to Write Less Java Code and Do More (Effective Java Hacks) 10 Career Mistakes Every Java Developer Should Avoid 10 Java One-Liners That Will Make You Look Like a Pro 🚀 Top 7 Refactoring Techniques to Clean Up Your Java Code Stream API Refactoring Tricks for Legacy Code How to Write Better Java Methods (Short, Clear, Powerful) Java Methods Be
🌐
DZone
dzone.com › data engineering › data › string.valueof(object) vs. objects.tostring(object)
String.valueOf(Object) Vs. Objects.toString(Object)
August 28, 2018 - Let's get to it! Both methods String.valueOf(Object) and Objects.toString(Object) essentially do the same thing: call the toString() method on a passed-in object. This is the case as long as it's not null or it doesn't return the string "null" ...
🌐
Coderanch
coderanch.com › t › 381829 › java › Casting-Object-String
Casting Object[] into String[] (Java in General forum at Coderanch)
Sounds a bit mad. Note that a cast doesn't change the object. So if you passed an Object[] to a method that expected a String[], the array couldn't be converted to a String[] at all, because an object can't change its type. Also remember that Java is multi-threaded.
🌐
Couchbase
couchbase.com › java sdk
Convert Document Object to String - Java SDK - Couchbase Forums
April 12, 2018 - Hi, I was able to read a user document from couchbase DB. when I convert the user object to string, I can able to see all meta data stuff as shown below. how can i get rid of that when converting object to string? I’m using ObjectMapper to convert object to string. something like this mapper.writeValueAsString(Object); Please advise “data”:{“nodeType”:“OBJECT”,“object”:true,“array”:false,“float”:false,“null”:false,“containerNode”:true,“integralNumber”:false,“floatingPointNumber”:false,“valueN...