AP® Computer Science A glossary
compareTo
Course: AP® Computer Science A Shows up in: Unit 1: Using Objects and Methods
The String method compareTo(String other): negative if this comes first alphabetically, 0 if equal, positive if this comes later.
Appears in the course and exam description (CED): 1.15.B.2
Read a.compareTo(b) < 0 as “a comes before b”. Capital letters come before lowercase ones, but exam questions usually use one case.
System.out.println("cat".compareTo("dog") < 0);
System.out.println("pear".compareTo("pear"));
Output:
true
0 Learn it properly, with a checkpoint 1.15 String Manipulation