S
sss.zhou
I want write an function to convert the abc_def_gh to AbcDefGh.
What I thought was, but I think it is very unefficient
String[] nameWords = name.split("_");
StringBuffer className = new StringBuffer();
for (int i=0; i<nameWords.length; i++) {
if (nameWords.length() > 0) {
char c = nameWords.charAt(0);
className.append(Character.toUpperCase(c));
className.append(nameWords.substring(1));
}
}
then the className.toString() is what I need.
And can you tell me some efficient way of doing this?
I tried to use the regular expression.
name.replaceAll("[a-z]{1}_", "what here?"), but I can't write the
second arguments.
What I thought was, but I think it is very unefficient
String[] nameWords = name.split("_");
StringBuffer className = new StringBuffer();
for (int i=0; i<nameWords.length; i++) {
if (nameWords.length() > 0) {
char c = nameWords.charAt(0);
className.append(Character.toUpperCase(c));
className.append(nameWords.substring(1));
}
}
then the className.toString() is what I need.
And can you tell me some efficient way of doing this?
I tried to use the regular expression.
name.replaceAll("[a-z]{1}_", "what here?"), but I can't write the
second arguments.