
15 Java String Method Questions I Practiced — Here's What I Actually Learned
15 Java String Method Questions I Practiced — Here's What I Actually Learned I've been learning Java for a while now, and strings are everywhere. But knowing that String exists and actually knowing how to use it in real situations are two very different things. Here's everything I picked up, question by question. Q1 — Why Does Login Fail Even When the Password is Correct? Scenario: User types Admin123 (with a trailing space). Login fails even though the password matches. This one is so common in real applications and nobody talks about it enough. The fix is .trim() — it removes all leading and trailing whitespace from a string before you compare it. if ( password . equals ( CheckPassword . trim ())) { System . out . println ( "Login Success" ); } What I learned: Never compare user input directly. Always .trim() first. Users accidentally add spaces all the time — especially on mobile keyboards. Q2 — UI Sends "Vijay" but Database Has "vijay" — How to Compare Safely? Scenario: The UI send
Continue reading on Dev.to
Opens in a new tab




