fork download
  1.  
  2. class Ideone
  3. {
  4. public static void main (String[] args) throws java.lang.Exception
  5. {
  6. // conversion
  7. String s = new String(String.valueOf(19));
  8. System.out.println(s);
  9.  
  10. String s1 = "Ishika";
  11. byte[] arr = s1.getBytes(); // gives ASCII values for all chars in the string
  12. for(byte b: arr)
  13. System.out.print(b + ",");
  14. System.out.println();
  15.  
  16. // advance methods
  17. String s2 = new String("Hello");
  18. String s3 = s2; // s2 and s3 points to string in heap memory
  19. String s4 = s2.intern(); // s4 will point to string literal created in string pool
  20. System.out.println(s2 == s3);
  21. System.out.println(s2 == s4);
  22.  
  23. String name = "Ishi";
  24. int age = 26;
  25. System.out.println(String.format("Hello %s, your age is %s", name, age));
  26. }
  27. }
Success #stdin #stdout 0.13s 56260KB
stdin
Standard input is empty
stdout
19
73,115,104,105,107,97,
true
false
Hello Ishi, your age is 26