String valueOf()

Ads
 

String valueOf()

This page discusses - String valueOf()

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.

Ads

Ads