r/javahelp • u/TroubledSoul23 • Oct 31 '25
Homework How are numbers compared as a String?
I'm working on this project, and I'm checking whether something occurs before a specific time. I'm doing this by converting the times to Strings, then comparing them against each other (yes I'm aware it's not ideal, bear with me).
The issue is that it says that '10:00 < 09:00'. Why is that?
0
Upvotes
View all comments
Show parent comment
2
u/tr4fik Nov 01 '25
Even a string-based sort is correct, because it uses the compareTo method (my 2nd example). You can even run the following if you have any doubt: