regex - replace underscore lowercase with uppercase

前端 未结 4 578
误落风尘
误落风尘 2021-01-17 22:36

I\'ve wondering is there a regex pattern that i could use to convert a pattern which is an underscore and a lowercase letter into an uppercase letter. I\'m trying to generat

4条回答
  •  滥情空心
    2021-01-17 23:18

    Maybe you want to use Google Guava:

    Code:

    import static com.google.common.base.CaseFormat.LOWER_CAMEL;
    import static com.google.common.base.CaseFormat.LOWER_UNDERSCORE;
    
    public class Main {
        public static void main(String[] args) {
            String str = "load_id,policy_id,policy_number";
            for(String columnName : str.split(",")) {
                System.out.println(LOWER_UNDERSCORE.to(LOWER_CAMEL, columnName));
            }
        }
    }
    

    Output:

    loadId
    policyId
    policyNumber
    

提交回复
热议问题