Compare package labels as strings

A warehouse stores package labels as Java strings. Their lexicographic order compares corresponding characters from left to right. For String.compareTo, the first differing characters determine the result: subtract the argument character's value from the receiver character's value. If one string is a prefix of the other, subtract the argument's length from the receiver's length.


Use these character values: '1' is 49, '8' is 56, 'R' is 82 and 'r' is 114. Comparisons are case sensitive. Complete the table with exact integer return values, rather than just their signs. No units apply.

Method callInteger result
"R8".compareTo("R14")
"R14".compareTo("R1")
"R1".compareTo("R14")
"R8".compareTo("r8")
"R14".compareTo("R14")

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Comparable Questions: