capitalize method
Returns a copy of this string having its first letter uppercased, or the original string, if it's empty or already starts with a upper case letter.
print('abcd'.capitalize()) // Abcd
print('Abcd'.capitalize()) // Abcd
Implementation
String capitalize() {
switch (length) {
case 0:
return this;
case 1:
return toUpperCase();
default:
return this[0].toUpperCase() + substring(1);
}
}