Prints true:false:false:false
The first comparison is true because myStr and myTextBlk1 are equal (text block doesn't include trailing new lines if there is no content after the last quote). The second and third comparisons are false because myTextBlk2 includes a newline character at the end, making it different from myStr and myTextBlk1. The last comparison is false because, despite interning, myTextBlk1 and myTextBlk2 are not equal due to the newline character in myTextBlk2.
right option is D. copy paste into https://editor.javadevjournal.com/java-17-compiler.html and see for yourself:
public class Main{
public static void main(String[] args){
String myStr = "Hello Java 17";
String myTextBlk1 ="""
Hello Java 17""";
String myTextBlk2 ="""
Hello Java 17
""";
System.out.print(myStr.equals(myTextBlk1)+":");
System.out.print(myStr.equals(myTextBlk2)+":");
System.out.print(myTextBlk1.equals(myTextBlk2)+":");
System.out.println(myTextBlk1.intern() == myTextBlk2.intern());
}
}
I think the right option is C. true:false:true:true
upvoted 1 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
xplorerpj
7 months, 1 week agoc6437d5
10 months, 2 weeks agoBharadwaj240796
11 months, 4 weeks agotestostaws
1 year agosupersquax
1 year agomeltedolive
1 year agoTojose
1 year ago