‹ 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?
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 |
- acharAt( )
- bequals( )
- cequalsIgnoreCase( )
- dstartsWith( )
Answer
Answer
AICorrect 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.
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 7.