Oracle
1Z0-803 · Question #231
Given: public class Equal { public static void main(String[] args) { String str1 = "Java"; String[] str2 = {"J","a","v","a"}; String str3 = ""; for (String str : str2) { str3 = str3+str; } boolean b1
The correct answer is B. false, true. == strict equality. equals compare state, not identity.
Working with Selected Classes from the Java API
Question
Given:
public class Equal { public static void main(String[] args) { String str1 = "Java"; String[] str2 = {"J","a","v","a"}; String str3 = ""; for (String str : str2) { str3 = str3+str; } boolean b1 = (str1 == str3); boolean b2 = (str1.equals(str3)); System.out.print(b1+", "+b2); } What is the result?
Options
- Atrue, false
- Bfalse, true
- Ctrue, true
- Dfalse, false
How the community answered
(47 responses)- A11% (5)
- B83% (39)
- C4% (2)
- D2% (1)
Explanation
== strict equality. equals compare state, not identity.
Topics
#String comparison#equals()#== operator#String concatenation
Community Discussion
No community discussion yet for this question.