Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java String-examples String valueOf()

Related Tutorials


 
 

Share on Google+Share on Google+

String valueOf()

Advertisement
This page discusses - String valueOf()

String valueOf()

     

In this section, you will get the detailed explanation about the valueOf() method of String class. We are going to use valueOf() method of String class in Java. The description of the code is given below for the usage of the method.

Description of the code:

This method creates a new String object containing the string representation of a double, float, short, byte, integer, long etc. As shown in the program code below taken strings of different types as long, short, integer, byte etc and then we have applied the valueOf() method to get a string object. The representation is exactly the one returned by the Double.toString(), Long.tostring(), Short.toString(), Float.toString() method of one argument etc.

Here is the code of the program: 

public class strvalueOf{
  public static void main(String args[]) {
  Integer i = Integer.valueOf("862");
  Long l = Long.valueOf("228693");
  Byte b = Byte.valueOf("55");
  Short s = Short.valueOf("9");
  Float f = Float.valueOf("852.256");
  Double d = Double.valueOf("259873.147369222");
 
  System.out.println(i);
  System.out.println(l);
  System.out.println(b);
  System.out.println(s);
  System.out.println(f);
  System.out.println(d);
  }
  }

Output of the program:

C:\unique>javac strvalueOf.java

C:\unique>java strvalueOf
862
228693
55
9
852.256
259873.147369222

C:\unique>

Download this example.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 17, 2011

Related Tutorials

Discuss: String valueOf()  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
fatemeh
April 21, 2013
thank you for informations.

i need a file for learning css&asp.net also java. can you help me?
DMCA.com