What's the best way to convert a "PascelCase"
string to all upper case separated by underscore like "Pascel_CASE"
. I wrote this code which works:
private static String pascelCaseToUpperCaseSeparatedByUnderscore(String s) {
String[] values = s.split("(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])");
for (int i = 0, len = values.length; i < len; i++) {
values[i] = values[i].toUpperCase();
}
return String.join("_", values);
}
However, is there better way say, using a library, to do this?