Top Description Constructors Methods
org.apache.commons.text

public Class CaseUtils

extends Object
Class Inheritance
Imports
java.util.HashSet, .Set, org.apache.commons.lang3.ArrayUtils, .StringUtils

Case manipulation operations on Strings that contain words.

This class tries to handle null input gracefully. An exception will not be thrown for a null input. Each method documents its behavior in more detail.

Since
1.2

Constructor Summary

AccessConstructor and Description
public
CaseUtils()

CaseUtils instances should NOT be constructed in standard programming.

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

camelCase of String, null if null String input
toCamelCase
(String
the String to be converted to camelCase, may be null
str
,
final boolean
boolean that determines if the first character of first word should be title case.
capitalizeFirstLetter
,
final char...
set of characters to determine capitalization, null and/or empty array means whitespace
delimiters
)

Converts all the delimiter separated words in a String into camelCase, that is each word is made up of a title case character and then a series of lowercase characters.

private static Set<Integer>

Returns:

Set
toDelimiterSet
(final char[]
set of characters to determine capitalization, null means whitespace
delimiters
)

Converts an array of delimiters to a hash set of code points.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

CaseUtilsback to summary
public CaseUtils()

CaseUtils instances should NOT be constructed in standard programming. Instead, the class should be used as CaseUtils.toCamelCase("foo bar", true, new char[]{'-'});.

This constructor is public to permit tools that require a JavaBean instance to operate.

Method Detail

toCamelCaseback to summary
public static String toCamelCase(String str, final boolean capitalizeFirstLetter, final char... delimiters)

Converts all the delimiter separated words in a String into camelCase, that is each word is made up of a title case character and then a series of lowercase characters.

The delimiters represent a set of characters understood to separate words. The first non-delimiter character after a delimiter will be capitalized. The first String character may or may not be capitalized and it's determined by the user input for capitalizeFirstLetter variable.

A null input String returns null.

A input string with only delimiter characters returns "".

Capitalization uses the Unicode title case, normally equivalent to upper case and cannot perform locale-sensitive mappings.
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"
CaseUtils.toCamelCase(" @", false, new char[]{'@'})                = ""
Parameters
str:String

the String to be converted to camelCase, may be null

capitalizeFirstLetter:boolean

boolean that determines if the first character of first word should be title case.

delimiters:char[]

set of characters to determine capitalization, null and/or empty array means whitespace

Returns:String

camelCase of String, null if null String input

toDelimiterSetback to summary
private static Set<Integer> toDelimiterSet(final char[] delimiters)

Converts an array of delimiters to a hash set of code points. Code point of space(32) is added as the default value. The generated hash set provides O(1) lookup time.

Parameters
delimiters:char[]

set of characters to determine capitalization, null means whitespace

Returns:Set<Integer>

Set