
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 0.60 KB | hits: 10 | expires: Never
String initialising in Java
String str1 = "hello";
String str2 = "hello";
String str1 = "Hello";
String str2 = "Hello";
System.out.print(str1 == str2);
String str1 = "Hello";
String str2 = new String("Hello");
System.out.print(str1 == str2);
String str1 = "hello";
char data[] = {'h', 'e', 'l', 'l', 'o'};
String str = new String(data);
String str = "hello";
String str1 = new String(str);
String str2 = new String(str);
assert: str1 != str2;
//Force strings into constant pool
String str3 = str1.intern();
String str4 = str2.intern();
assert: str == str3;
assert: str3 == str4;