Data Conversion Using valueOf() In Java.

Java 8Object Oriented ProgrammingProgramming

Java String class provides several variants of valueOf() method. These accept various data types and convert them into String.

Example

Live Demo

public class Sample {
   public static void main(String args[]){
      int i = 200;
      float f = 12.0f;
      char c = 's';
      char[] ch = {'h', 'e', 'l', 'l', 'o'};
      String data = String.valueOf(i);
      System.out.println(String.valueOf(i));
      System.out.println(String.valueOf(f));
      System.out.println(String.valueOf(c));
      System.out.println(String.valueOf(ch));
   }
}

Output

200
12.0
s
hello
raja
Published on 12-Feb-2018 09:01:51
Advertisements