The Value of a String with String.valueOf method : Convert to String « Data Type « Java






The Value of a String with String.valueOf method

  
        
class MainClass {
  public static void main(String[] args) {
    String s = String.valueOf(false);
    System.out.println(s);

    s = String.valueOf('A');
    System.out.println(s);

    char[] c = { 'a', 'b', 'c' };

    s = String.valueOf(c);
    System.out.println(s);

    s = String.valueOf(c, 0, 2);
    System.out.println(s);

    s = String.valueOf(3.5d);
    System.out.println(s);

    s = String.valueOf(2.5f);
    System.out.println(s);

    s = String.valueOf(59);
    System.out.println(s);

    s = String.valueOf(8000l);
    System.out.println(s);
  }
}

   
  








Related examples in the same category

1.Convert an int value to String: Integer.toString(i)
2.Use toString method of Integer class to conver Integer into String.
3.Convert an int value to String: new Integer(i).toString()
4.Convert an int value to String: concatenate string to an int value
5.Convert from integer to String
6.Convert a byte array to a Hex string
7.To catch illegal number conversion, try using the try/catch mechanism.