Written by the Fiveable Content Team • Last updated August 2025
Verified for the 2026 exam
Verified for the 2026 exam•Written by the Fiveable Content Team • Last updated August 2025
Definition
The `compareTo()` method is used to compare two strings lexicographically (i.e., based on their alphabetical order). It returns an integer value that indicates the difference between the two strings.