Does anyone know of a library that would allow me to convert a camel case string to an uppercase with underscore string?
e.g. addressId ==> ADDRESS_ID
You can create your own method:
public static String toUpperCaseWithUnderscore(String input) {
if(input == null) {
throw new IllegalArgumentException();
}
StringBuilder sb = new StringBuilder();
for(int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if(Character.isUpperCase(c)) {
if(i > 0) {
sb.append('_');
}
sb.append(c);
} else {
sb.append(Character.toUpperCase(c));
}
}
return sb.toString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With