string - how to convert "user_id" to "userId" in Java? -
this question has answer here:
convert string camelcase
eg: "user_id" "userid" "user_name" "username" "country_province_city" "countryprovincecity"
how in easy way?
ps:"country_province_city" should "countryprovincecity" not "countryprovincecity"
i use loop , stringbuilder
. like
string[] arr = { "user_id", "user_name", "country_province_city" }; (string str : arr) { stringbuilder sb = new stringbuilder(str); int pos; while ((pos = sb.indexof("_")) > -1) { string ch = sb.substring(pos + 1, pos + 2); sb.replace(pos, pos + 2, ch.touppercase()); } system.out.printf("%s = %s%n", str, sb); }
and (requested)
user_id = userid user_name = username country_province_city = countryprovincecity
Comments
Post a Comment