Java Program to Convert Object to String Last Updated : 08 Dec, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 two types of class in java, i.e. user-defined class and predefined class such as StringBuilder or StringBuffer of whose objects can be converted into the string. Approaches: Converting User-defined class object to StringConverting StringBuilder(Predefined class) object to String Method 1: Using toString() method or String.valueOf(object_name) method. Java // Java Program to convert pre defined class object // (Helper class) to string using value() method class GFG { // Main driver method public static void main(String[] args) { // Object of helper class Helper help = new Helper(); // converting object to string // using toString() method String s1 = help.toString(); // converting object to string // using valueOf() method String s2 = String.valueOf(help); // Printing the converted string System.out.println( "Converted string object || using toString() Method: " + s1); // Printing the converted string System.out.println( "Converted string object || using valueOf() Method: " + s2); } } class Helper { // To make class object in main } OutputConverted string object || using toString() Method: Helper@214c265e Converted string object || using valueOf() Method: Helper@214c265e Method 2: Converting StringBuilder(Predefined class) object to String. The StringBuilder in Java represents a mutable sequence of characters. Since the String Class in Java creates an immutable sequence of characters, the StringBuilder class provides an alternative to String Class, as it creates a mutable sequence of characters. Class Hierarchy: java.lang.Object ↳ java.lang ↳ Class StringBuilder Example: Java // Java Program to convert StringBuilder object to string class GFG { // Main driver method public static void main(String[] args) { /* String taken for consideration */ String s = "Geeks For Geeks"; // Passing string s to StringBuilder class object StringBuilder sb = new StringBuilder(s); // Converting the object to string // Converting StringBuilder to string String objToString = sb.toString(); // Printing the strings to verify System.out.println("String: " + s); System.out.println("Converted String: " + objToString); } } OutputString: Geeks For Geeks Converted String: Geeks For Geeks Comment More infoAdvertise with us Next Article Java Program to Convert String to Object L lavishgarg26 Follow Improve Article Tags : Java Technical Scripter Java Programs Technical Scripter 2020 Practice Tags : Java Similar Reads Java Program to Convert String to Object In-built Object class is the parent class of all the classes i.e each class is internally a child class of the Object class. So we can directly assign a string to an object. Basically, there are two methods to convert String to Object. Below is the conversion of string to object using both of the me 2 min read Java Program to Convert Long to String The long to String conversion in Java generally comes in need when we have to display a long number in a GUI application because everything is displayed in string form. In this article, we will learn about Java Programs to convert long to String. Given a Long number, the task is to convert it into a 4 min read Java Program to Convert String to Long To convert a String to Long in Java, we can use built-in methods provided by the Long class. In this article, we will learn how to convert String to Long in Java with different methods. Example:In the below example, we use the most common method i.e. Long.parseLong() method to convert a string to a 3 min read Java Program to Convert JSON String to JSON Object Gson is a Java library that can be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects whose source code we don't have. It provides the support to transfer data in between different programming languages modules. JSON S 2 min read Java Program to Convert Date to String The date type object can be converted to a string in Java using a large variety of in-built classes available in Java. Given a date, we need to convert the date to a given format of the string. Examples: Input: date = â2020-11-13âOutput: 2020-11-13 Input: date = â2020-12-14âOutput: 2020-12-14 Method 3 min read Java Program to Convert Enum to String Given an enum containing a group of constants, the task is to convert the enum to a String. Methods: We can solve this problem using two methods: Using name() MethodUsing toString() Method Let us discuss both of them in detail and implementing them to get a better understanding of the same. Method 1 2 min read Like