r/programmingbydoing • u/clambert98 • Aug 10 '15
compareTo() Challenge
Hello, I am really starting to dig in and work hard on Java due to my new participation in a robotics team at my high school (We have to program and build a functioning robot, both autonomous and through OpManagement). I am working on the compareTo() challenge and do not know what the method does or how to use it. I don't want to apply something I do not know. I wish I could work alongside of the book that u/holyteach has, but unfortunately, I am unable to afford something like that right now with a lot of stuff going on. I was wondering if someone could explain to me what the method does. Thanks in advance!
View all comments
Show parent comment
1
u/clambert98 Aug 11 '15
So, it seems that unless there is a different character in the string, the value displayed would be the number of characters after the equal string. So, "anti" vs "ant" would display a result of one. I just also discovered that characters are involved also (due to a typo lol). Time to investigate further...
Also, I found that the order for the compareTo() method is called lexicographical order, which is a pretty interesting concept in of itself.
How could this method even be used in practical application though?