public class SentenceFormatter extends Object
Constants define instances of common formatters. The following is an example
using the words abc
, def
and ghi
.
Formatter | Example |
---|---|
LOWER_CAMEL_CASE |
abcDefGhi |
LOWER_KEBAB_CASE |
abc-def-ghi |
LOWER_SNAKE_CASE |
abc_def_ghi |
LOWER_WHITE_SPACE |
Abc def ghi |
UPPER_CAMEL_CASE |
AbcDefGhi |
UPPER_KEBAB_CASE |
ABC-DEF-GHI |
UPPER_SNAKE_CASE |
ABC_DEF_GHI |
UPPER_WHITE_SPACE |
Abc Def Ghi |
Modifier and Type | Field and Description |
---|---|
static SentenceFormatter |
LOWER_CAMEL_CASE
Lower Camel Case formatter
Example: abcDefGhi
Words are translated to title case, except the first words, which is
translated to lower case.
|
static SentenceFormatter |
LOWER_KEBAB_CASE
Lower Kebab Case formatter
Example: abc-def-ghi
Words are translated to lower case and are separated by minus character.
|
static SentenceFormatter |
LOWER_SNAKE_CASE
Lower Snake Case formatter
Example: abc_def_ghi
Words are translated to lower case and are separated by underscore character.
|
static SentenceFormatter |
LOWER_WHITE_SPACE
Lower White Space formatter
Example: Abc def ghi
Words are translated to lower case, except the first word, which is
translated to title case, and are separated by white space character.
|
static SentenceFormatter |
UPPER_CAMEL_CASE
Upper Camel Case formatter
Example: AbcDefGhi
Words are translated to title case.
|
static SentenceFormatter |
UPPER_KEBAB_CASE
Upper Kebab Case formatter
Example: ABC-DEF-GHI
Words are translated to upper case and are separated by minus character.
|
static SentenceFormatter |
UPPER_SNAKE_CASE
Upper Snake Case formatter
Example: ABC_DEF_GHI
Words are translated to upper case and are separated by underscore character.
|
static SentenceFormatter |
UPPER_WHITE_SPACE
Upper White Space formatter
Example: Abc Def Ghi
Words are translated to title case and are separated by white space
character.
|
Constructor and Description |
---|
SentenceFormatter(Function<String,String> convertFirstWord,
String separator,
Function<String,String> convertSubsequentWords)
Creates a new
SentenceFormatter instance. |
Modifier and Type | Method and Description |
---|---|
String |
format(List<String> words)
Formats the list of given words using the specified converter functions and
separator.
|
String |
format(String... words)
Formats the list of given words using the specified converter functions and
separator.
|
Function<String,String> |
getConvertFirstWord()
Function to convert the first word
|
Function<String,String> |
getConvertSubsequentWords()
Function to convert all words except the first word
|
String |
getSeparator()
Separator character between words
|
List<String> |
parse(String sentence)
Splits the given sentence into words using the separator.
|
public static final SentenceFormatter LOWER_CAMEL_CASE
Example: abcDefGhi
Words are translated to title case, except the first words, which is translated to lower case.
public static final SentenceFormatter LOWER_KEBAB_CASE
Example: abc-def-ghi
Words are translated to lower case and are separated by minus character.
public static final SentenceFormatter LOWER_SNAKE_CASE
Example: abc_def_ghi
Words are translated to lower case and are separated by underscore character.
public static final SentenceFormatter LOWER_WHITE_SPACE
Example: Abc def ghi
Words are translated to lower case, except the first word, which is translated to title case, and are separated by white space character.
public static final SentenceFormatter UPPER_CAMEL_CASE
Example: AbcDefGhi
Words are translated to title case.
public static final SentenceFormatter UPPER_KEBAB_CASE
Example: ABC-DEF-GHI
Words are translated to upper case and are separated by minus character.
public static final SentenceFormatter UPPER_SNAKE_CASE
Example: ABC_DEF_GHI
Words are translated to upper case and are separated by underscore character.
public static final SentenceFormatter UPPER_WHITE_SPACE
Example: Abc Def Ghi
Words are translated to title case and are separated by white space character.
public SentenceFormatter(Function<String,String> convertFirstWord, String separator, Function<String,String> convertSubsequentWords)
SentenceFormatter
instance.convertFirstWord
- Function to convert the first wordseparator
- Separator character between wordsconvertSubsequentWords
- Function to convert all words except the first wordpublic String format(String... words)
words
- list of wordspublic String format(List<String> words)
words
- list of wordspublic List<String> parse(String sentence)
sentence
- the sentence to be splittedpublic Function<String,String> getConvertFirstWord()
public String getSeparator()
Copyright © 2025. All rights reserved.