ArrayConverter

The ArrayConverter class provides methods to create an array from a set of values.

Description

The ArrayConverter class provides methods to create an array from a set of values. These values can be in the form of a list, a single value or a string of comma-delimited values.

Static methods

listToArray

Converts a list into an array object with an empty array as default. Strings with comma-delimited values are split into array of strings. See toArray

public static List listToArray(Object value)

  • value: Object - list to convert.
  • returns: List - array object or empty array when value is null.

    toArray

    Converts a value into an array object with an empty array as default. Single values are converted into arrays with a single element.

    public static List toArray(Object value)

    • value: Object - value to convert.
    • returns: List - List of objects.

      toArrayWithDefault

      Converts a value into an array object with a specified default. Single values are converted into arrays with a single element.

      public static List toArrayWithDefault(Object value, List defaultValue)

      • value: Object - value to convert.
      • defaultValue: List - default array object.
      • returns: List - list of objects.

        toNullableArray

        Converts a value into an array object. Single values are converted into arrays with a single element.

        public static List toNullableArray(Object value)

        • value: Object - value to convert.
        • returns: List - array object or null when value is null.

          Examples

          {
            List<Object> value1 = ArrayConverter.toArray(1);        // Result: [1]
            List<Object> value2 = ArrayConverter.listToArray("1,2,3"); // Result: ["1", "2", "3"]
            }