Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 0.60 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. String initialising in Java
  2. String str1 = "hello";
  3. String str2 = "hello";
  4.        
  5. String str1 = "Hello";  
  6.  String str2 = "Hello";
  7.  System.out.print(str1 == str2);
  8.        
  9. String str1 = "Hello";  
  10. String str2 = new String("Hello");
  11. System.out.print(str1 == str2);
  12.        
  13. String str1 = "hello";
  14.        
  15. char data[] = {'h', 'e', 'l', 'l', 'o'};
  16. String str = new String(data);
  17.        
  18. String str  = "hello";
  19. String str1 = new String(str);
  20. String str2 = new String(str);
  21. assert: str1 != str2;
  22. //Force strings into constant pool
  23. String str3 = str1.intern();
  24. String str4 = str2.intern();
  25. assert: str == str3;
  26. assert: str3 == str4;