‹ Back to the paper
Passwords are stored as two Strings-one is the user entered password saved in StringA, the other is a password stored by the system in StringB.
If StringA must be checked with StringB, for validity, which one of the following String functions are needed to be used?
Question 7
1 mark
Computer ScienceISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024)MCQArrays, Strings
Choose the correct option.
String Description StringA Password entered by the user StringB Password stored by the system…
| String | Description |
|---|---|
| StringA | Password entered by the user |
| StringB | Password stored by the system |
- (a)charAt( )
- (b)equals( )
- (c)equalsIgnoreCase( )
- (d)startsWith( )
Answer
Answer
Correct option: b
Answer: (b) equals( ).
A password check needs an exact, case-sensitive comparison, which String's equals( ) method gives. equalsIgnoreCase( ) would wrongly accept passwords differing only in case, and charAt( )/startsWith( ) do not compare the whole string.