Java中将字符串转为驼峰格式

本文不再更新,可能存在内容过时的情况,实时更新请移步我的新博客: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指定连词符。

原文地址:https://www.cnblogs.com/cobcmw/p/12035885.html