String equality Flashcards
What issue arises when using ==
to compare string values in Java?
a) It compares the actual string values
b) It compares the memory references of the strings
c) It automatically checks string length first
d) It ignores case sensitivity
b) It compares the memory references of the strings
Which method should be used to compare string values for equality in Java?
a) compareTo()
b) equalsIgnoreCase()
c) equals()
d) substring()
c) equals()
What is the purpose of the endsWith()
method in Java?
a) To check if a string starts with a specific prefix
b) To determine if a string contains a specific sequence of characters
c) To verify if a string ends with a specific suffix
d) To change the case of a string
c) To verify if a string ends with a specific suffix
In the isBusinessEmail
method, which domain ending will cause an email to be considered invalid?
a) @largecorp.com
b) @gmail.com
c) @business.com
d) @company.com
b) @gmail.com
What does the startsWith()
method do?
a) It checks if a string ends with a specific suffix
b) It verifies if a string starts with a specific prefix
c) It checks if a string contains a specific substring
d) It removes leading spaces from the string
b) It verifies if a string starts with a specific prefix
Which of the following would cause isBusinessEmail()
to return true?
a) An email ending with .edu
b) An email ending with @gmail.com
c) An email ending with @largecorp.com
d) An email ending with @personal.com
c) An email ending with @largecorp.com
What does the contains()
method do in Java?
a) It checks if a string starts with a specific prefix
b) It verifies if a string contains a specific sequence of characters
c) It changes the case of the string
d) It removes certain characters from the string
b) It verifies if a string contains a specific sequence of characters
How does the substring()
method work when called with two arguments?
a) It extracts a part of the string from the beginning to the end
b) It extracts a substring between two specified indices
c) It replaces part of the string with another
d) It trims leading and trailing spaces
b) It extracts a substring between two specified indices
What will the output be when firstName.equals("Victoria")
is called and firstName
is equal to Victoria
?
a) Your name is Victoria!
b) Sorry, your name is NOT Victoria.
c) An error message
d) First name not found
a) Your name is Victoria!
What is the expected output when phoneNumber2.contains("-188-")
is true?
a) No output is generated
b) The phone number contains 188!
c) This is a valid 188 number!
d) Error in phone number check
c) This is a valid 188 number!