Home Java Java-conversion Convert Object To String



Convert Object To String
Posted on: July 5, 2007 at 12:00 AM
In this section, you will learn to convert an object to a string.

Convert Object To String

     

In this section, you will learn to convert an object to a string. Object is a class of java.lang package.

Code Description:

This program helps you in converting an object type data into a string type data. The toString() method returns a string representation of the object. So, we get the an object type data is 10 and this program converts into a string type data as a '10'. 

Here is the code of this program:

import java.io.*;
import java.lang.*;

public class ObjectToString{
  public static void main(String[] args) {
  Object obj = 10;
  String s = obj.toString();
  System.out.println("String value is: = " + s);
  }
}

 Download of this program:

Output of this program given below.

C:\corejava>java ObjectToString
String value is:=10
C:\corejava>
_

Related Tags for Convert Object To String:
cstringdataobjectconvertiohelpmethodgettypereturnintthistostringprogramtorampresentationerepresentationpeinconvertingasmntpstrososjesmeintoobjprosurnsoatispreandstrreprrtrtsssriringthstatijeprndonogro


More Tutorials from this section

Ask Questions?    Discuss: Convert Object To String   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.