• 大写加下划线转化成小写驼峰形式


    例如把RESULT_LIST转化成resultList字符串

    第一:通过input.toLowerCase().split(spliter)用‘_’把字符串分割成多个小写字母的数组。

    第二:把第一个数组以外的数组首字母变大写。

    第三:通过append()拼接字符串。

     1 //型如XXX_YYY_ZZZ的子串改为xxxYyyZxx的子串
     2     private static String slashToFirstLetterUpper(String input) {
     3         String spliter = "_";
     4         StringBuffer output = new StringBuffer();
     5         String[] words = input.toLowerCase().split(spliter);
     6         for (int i = 0; i < words.length; i++) {
     7             if (i != 0) {
     8                 output.append(fistLetterToUpper(words[i]));
     9             }
    10             else {
    11                 output.append(words[i]);
    12             }
    13         }
    14 
    15         return output.toString();
    16     }
    17 
    18     private static String fistLetterToUpper(String input) {
    19         if (input == null)
    20             return "";
    21         if (input.length() <= 0)
    22             return "";
    23 
    24         return input.substring(0, 1).toUpperCase() + input.substring(1);
    25     }
  • 相关阅读:
    python中xrange和range的异同
    Python:使用threading模块实现多线程编程
    python Queue模块
    Python中pass语句的作用
    Python的作用域
    eclipse颜色配置
    protobuf
    python调试总结
    chardet安装
    Windows下搭建PHP开发环境
  • 原文地址:https://www.cnblogs.com/whluan/p/12214414.html
Copyright © 2020-2023  润新知