zoukankan      html  css  js  c++  java
  • 大写加下划线转化成小写驼峰形式

    例如把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     }
  • 相关阅读:
    Druid数据库连接池源码分析
    彻底理解Java的Future模式
    CountDownLatch与CyclicBarrier
    Semaphore实现原理分析
    ThreadLocal类分析
    Atomic类和CAS
    synchronized VS Lock, wait-notify VS Condition
    Klass与Oop
    JVM类加载以及执行的实战
    123
  • 原文地址:https://www.cnblogs.com/whluan/p/12214414.html
Copyright © 2011-2022 走看看