Convert String[] array to boolean[] array using Apache Commons

This code example shows how to convert a string array to a boolean array. For this we use the Apache Commons Beanutils library that comes with quite a few converters for different data types. It also comes with a utility class containing methods to do conversions without directly using the converter for that specific type. That utility class is called ConvertUtils and the below example shows how to use it to convert a string array to a boolean array.

When using this library to convert a string value to a boolean value there are more values that is converted to true than if you do a conversion without the Beanutils library. Normally the string values “true” or “TRUE” is converted to a boolean value true, but here we can also use string values “yes”, “y” and “on” to get a boolean value that evaluates to true (and their respective uppercase variants).

The output from the code above is:

Search for more Java info on this site here:
Custom Search

Any thoughts or questions?