VOOZH about

URL: https://www.geeksforgeeks.org/dsa/output-java-programs-set-53-string-comparison/

⇱ Output of Java Programs | Set 53 (String Comparison) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Output of Java Programs | Set 53 (String Comparison)

Last Updated : 10 Sep, 2018
Prerequisite : String Comparison in Java 1. What should be the output of this program? a) true b) false c) 0 d) 1 Output:
b) false
Explanation: The startsWith() method is case sensitive “hello” and “Hello” are treated differently, hence false is stored in GfG2. 2. What should be the output of this program? a) true true b) false false c) true false d) false true Output:
d) false true
Explanation: The == operator compares two object references to see whether they refer to the same instance, where as equals() compares the content of the two objects. 3. What should be the output of this program? a) true true b) false false c) true false d) false true Output:
a) true true
Explanation: The == operator compares two object references to see whether they refer to the same instance but when using == with a string literal(not an instantiated String variable) will only compare the content of the strings. 4. What should be the output of this program? a) ab b) bc c) ca d) ac
d) ac
Explanation: compareTo() function returns zero when both the strings are equal, it returns a value less than zero if the invoking string is less than the other string being compared and value greater than zero when invoking string is greater than the string compared to. 5. What should be the output of this program? a) true true b) false false c) true false d) false true Output:
c) true false
Explanation: As we know that equal() method compares the content of the strings. GfG1 and GfG are having the same content. But as we know equal() is case sensitive, therefore GfG2 and GfG3 are different. 6. What should the output of this program? a) Hello b) World c) Helloworld d) Hello World Output:
d) Hello World
Explanation: append() method of class StringBuffer is used to concatenate the string representation to the end of invoking string.
Comment