Code: Select all
String a = "java";
char[] b = { 'j', 'a', 'v', 'a' };
String c = new String(b);
String d = a;
Code: Select all
1. (a == d)
2. (b == d)
3. (a == "java")
4. a.equals(c)
Why no.4 is correct? Don't get it.
Moderator: admin
Code: Select all
String a = "java";
char[] b = { 'j', 'a', 'v', 'a' };
String c = new String(b);
String d = a;
Code: Select all
1. (a == d)
2. (b == d)
3. (a == "java")
4. a.equals(c)
HTH,Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example:
String str = "abc";
is equivalent to:
char data[] = {'a', 'b', 'c'};
String str = new String(data);
Code: Select all
String s = "java";
Code: Select all
s.equals(new String("java"))
Code: Select all
s == new String("java")
Code: Select all
s == "java"
Users browsing this forum: No registered users and 98 guests