Scala String.toUpperCase
Convert a three-letter airport code to uppercase before comparing it with a timetable.
A simple example
String.toUpperCase
- Start with "ab"
- Do this Convert to uppercase
- Result "AB"
object Lesson {
def main(args: Array[String]): Unit = {
val value = "ab"
println(value.toUpperCase(java.util.Locale.ROOT))
}
}
AB
Syntax
label.toUpperCase(java.util.Locale.ROOT)
Run these examples in Scala
Save one example at a time as Lesson.scala. Use Scala 2.13 on JDK 21.
scalac Lesson.scala
scala LessonStandardize an airport code
A travel desk receives airport codes in mixed case from several forms. Convert the code to the required display case so it can be compared with the label on the boarding pass.
object Lesson {
def main(args: Array[String]): Unit = {
val label = "maa"
println(label.toUpperCase(java.util.Locale.ROOT))
}
}
MAA
The lowercase letters become MAA, the code displayed on the ticket.
Print an airport tag
A traveler types an airport abbreviation using a personal keyboard. The printed luggage tag must use the standard uppercase spelling so the code is easy to identify on the belt.
object Lesson {
def main(args: Array[String]): Unit = {
val value = "maa"
println(value.toUpperCase(java.util.Locale.ROOT))
}
}
MAA
All three ASCII letters become capitals.
Standardize a lab section
Two terminals can enter the same short label with different capitalization or padding. Normalize the incoming spelling before lookup so the stored identifiers can follow a consistent convention.
object Lesson {
def main(args: Array[String]): Unit = {
val value = "bio-2"
println(value.toUpperCase(java.util.Locale.ROOT))
}
}
BIO-2
The number and hyphen are unaffected.
What to watch for
Airport codes use ASCII. Names and other human text may need language-specific case handling.