本文不再更新,可能存在內容過時的情況,實時更新請移步我的新博客:Java中將字符串轉為駝峰格式;
使用CaseUtils 對Java字符串進行轉換為駝峰格式:
CaseUtils.toCamelCase(null, false) = null
CaseUtils.toCamelCase("", false, *) = ""
CaseUtils.toCamelCase(*, false, null) = *
CaseUtils.toCamelCase(*, true, new char[0]) = *
CaseUtils.toCamelCase("To.Camel.Case", false, new char[]{'.'}) = "toCamelCase"
CaseUtils.toCamelCase(" to @ Camel case", true, new char[]{'@'}) = "ToCamelCase"
CaseUtils.toCamelCase(" @to @ Camel case", false, new char[]{'@'}) = "toCamelCase"
構造方法:
public static String toCamelCase(String str,
boolean capitalizeFirstLetter,
char... delimiters)
其中:str為要轉換的字符串;capitalizeFirstLetter表示是否首字母大寫;delimiters指定連詞符。