C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Then: We can transform chars with a simple table lookup. No call to Character.toUpperCase is needed.
Java program that uses char lookup table
public class Program {
static char[] table = new char[128];
public static void main(String[] args) {
// Set up the lookup table.
for (int i = 0; i < 128; i++) {
// Get character for this int.
char c = (char) i;
// Convert to uppercase.
char result = Character.toUpperCase(c);
// Store in lookup table field.
table[c] = result;
}
// Loop over string characters.
String name = "Carrot123";
for (int i = 0; i < name.length(); i++) {
// Get char from lookup table based on string char.
char result = table[name.charAt(i)];
// Write results.
System.out.println(name.charAt(i) + "/" + result);
}
}
}
Output
C/C
a/A
r/R
r/R
o/O
t/T
1/1
2/2
3/3