fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. char chars[] = {'a', 'b', 'c', 'd'};
  13. String s = new String(chars);
  14. System.out.println(s);
  15.  
  16. String sNew = new String(chars, 1, 3);
  17. System.out.println(sNew);
  18.  
  19. String s1 = new String(chars);
  20. String s2 = new String(s1);
  21. System.out.println(s1);
  22. System.out.println(s2);
  23.  
  24. if (s1 == s2) {
  25. System.out.println("String s1 and s2 are same");
  26. } else if (s1.equals(s2)) {
  27. System.out.println("Contents of String s1 and s2 are same");
  28. }
  29.  
  30. String s3 = s2;
  31. if (s2 == s3) {
  32. System.out.println("String s2 and s3 are same");
  33. }
  34. if (s2.equals(s3)) {
  35. System.out.println("Contents of String s2 and s3 are same");
  36. }
  37. }
  38. }
Success #stdin #stdout 0.06s 47272KB
stdin
Standard input is empty
stdout
abcd
bcd
abcd
abcd
Contents of String s1 and s2 are same
String s2 and s3 are same
Contents of String s2 and s3 are same