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
Updated on 26-Feb-2020 09:53:23

Advertisements