Lecture 23
12
Comparing Strings
•
public
int
compareTo(String s) // not boolean
•
•
“hello”.compareTo(“help!”) -4 // = ‘l’ - ‘p’
•
“hello”.compareTo(“hell”)
1 // 5-4 (lengths)
•
•
x.compareTo(y) == 0 just when x.equals(y)
•
•
compareTo
is wonderful for sorting (alphabetizing)