Suppose that we have executed the following statements in a program. String titl
ID: 3883579 • Letter: S
Question
Suppose that we have executed the following statements in a program. String title = new String(“Drown by Junot Diaz”); String quietTitle = new String(“Drown by Junot Diaz”); String loudTitle = new String(“DROWN BY JUNOT DIAZ”); String emoTitle = new String(“DROWN!!!! By Junot Diaz”); String oddTitle = new String(“DrOwN By JuNoT DiAz”); Give the value (either true or false) for the statements in b) to f) a. title.equals(quietTitle) b. title.equalsIgnoreCase(quietTitle) c. title == quietTitle d. emoTitle.equalsIgnoreCase(oddTitle) e. loudTitle.equals(oddTitle)
Explanation / Answer
Actually the options are a to e not b to f
Given
String title = new String(“Drown by Junot Diaz”);
String quietTitle = new String(“Drown by Junot Diaz”);
String loudTitle = new String(“DROWN BY JUNOT DIAZ”);
String emoTitle = new String(“DROWN!!!! By Junot Diaz”);
String oddTitle = new String(“DrOwN By JuNoT DiAz”);
a. title.equals(quietTitle) : This will return true as both the values of title and quietTitle are same.
b. title.equalsIgnoreCase(quietTitle) : This will return true as both the values of title and quietTitle are same if cases are ignored also.
c. title == quietTitle : This will return false as we cannot compare the values of title and quietTitle using equality.
d. emoTitle.equalsIgnoreCase(oddTitle) : This will return false as the values of emoTitle and oddTitle contents are completely different irresepective of case.
e. loudTitle.equals(oddTitle): This will return false as the values of loudTitle and oddTitle contents are identical but the cases are different.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.