Java - String Value Convert

Introduction

String class overloaded valueOf() static method returns the string representation of the values of any primitive data type or any object.

For example,

Demo

public class Main {
  public static void main(String[] args) {
    String s1 = String.valueOf('C');  // s1 has "C"
    System.out.println(s1);//w  w w .  j  av a  2 s . c o  m
    
    String s2 = String.valueOf("10"); // s2 has "10"
    System.out.println(s2);
    
    String s3 = String.valueOf(true); // s3 has "true"
    System.out.println(s3);
    
    String s4 = String.valueOf(2028); // s4 has "2028"
    System.out.println(s4);
  }
}

Result