This is an implementation of optional arguments. It is used to provide an API where if you call it without the optional arguments it will proceed with sane (preferably) defaults:
String.splitByCharacterType(text); // splits the normal way
String.splitByCharacterType(text,CAMEL_CASE); // splits the alternative way
note: I've never used Apache StringUtils so my example above may be wrong but it's only to illustrate the use-case.
In some languages such as C++, the language directly provides syntax to support this use case:
char*[] splitByCharacterType(char* text, bool camelCase = 0) {
// ...
}
In other languages that have neither function overloading nor optional arguments the same use-case can be implemented using varargs. For example, in javascript you could do this:
function splitByCharacterType (text) {
var camelCase = false;
if (arguments.length > 1 && arguments[1] == true) camelCase = true;
// ...
}
In some languages, you're allowed to call a function with less than the expected number of arguments and the unspecified arguments will simply be given the value of null or undefined. For example, in javascript you can also do this:
function splitByCharacterType (text, camelCase) {
if (camelCase != undefined) {
// ..
}
else {
// ..
}
}
The idea of optional arguments is essentially similar to command line parameters for console applications. For example:
ls
the above invocation generates output you most commonly want but you can also do:
ls -l
for those times when you need more information.