You can process data in arrays and collections using the following library.

Note:

When using a collection format, some of the following methods which perform operations between two arrays or collections determine data type automatically based on Java defaults. For example, 3 is treated as integer, 3.5 as a double and c as a string. However, array comparison is based on the array data types.

#data.containsAll(new int[] {2,4,6,8,10}, new int[] {2,8}) returns as true because both are int arrays.

#data.containsAll(new int[] {2,4,6,8,10}, {2,8}) returns as true because the first argument is an int array and the second argument uses int by default.

#data.containsAll(new float[] {2.1,4.1,6.1,8.1,10.1}, {2.1,8.1}) returns as false because the first argument is a float array and the second argument is a double, which is the default for floating point numbers.

#data.containsAll(new double[] {2.1,4.1,6.1,8.1,10.1}, {2.1,8.1}) returns as true because the first argument is a double array and the second argument is treated as a double by default.

#data.containsAll({2.1,4.1,6.1,8.1,10.1}, {2.1,8.1}) returns as true because both arguments are collections and use the default data types.

String Description Input Output

int indexOf(Array <srcArray>, <valueToFind>)

where:

  • <srcArray> is the array to search through
  • <valueToFind> is the value to find.

Finds and returns the index of the valueToFind in the input array. Returns -1 if not found or if srcArray is null.

  1. #data.indexOf(new int[] {2,4,6,8,10}, 6)
  2. #data.indexOf({'This', 'is', 'String', 'collection'}, 'is')
  1. 2
  2. 1

boolean isNotEmpty(Array <srcArray>)

where <srcArray> is the array to check.

Checks if the input array is not empty and not null.

  1. #data.isNotEmpty(new int[] {2,4,6,8,10})
  2. #data.isNotEmpty({'This', 'is', 'String', 'collection'})
  1. true
  2. true

boolean containsAll(Array <srcData>, Array <searchData>)

where <searchData> is the array of values to be searched for in the <srcData> array.

Returns true if all elements of searchData are contained in srcData.

  1. #data.containsAll(new int[] {2,4,6,8,10}, new int[] {2,8})
  2. #data.containsAll(new int[] {2,4,6,8,10}, {2,8})
  3. #data.containsAll({2,4,6,8,10}, {2,9})
  4. #data.containsAll(new float[] {2.1,4.1,6.1,8.1,10.1}, {2.1,8.1})
  5. #data.containsAll(new double[] {2.1,4.1,6.1,8.1,10.1}, {2.1,8.1})
  1. true
  2. true
  3. false
  4. false
  5. true

boolean containsAny(Array <srcData>, Array <searchData>)

where <searchData> is the array of values to be searched for in the <srcData> array.

Returns true if there is at least one common element in both arrays.

  1. #data.containsAny({2,4,6,8,10}, {2,9,11})
  2. #data.containsAny(new int[] {2,4,6,8,10}, {2,9,11})
  3. #data.containsAny({2,4,6,8,10}, new int[] {1,9})
  1. true
  2. true
  3. false
Array removeAll(Array <srcData>, Array <dataToRemove>)

where <dataToRemove> is the array of values to be removed from the <srcData> array.

Removes the elements in dataToRemove from srcData and returns a new array.

  1. #data.removeAll(new int[] {2,4,6,8,10}, new int[] {2,6,11})
  2. #data.removeAll({2,4,6,8,10}, {2,6,11})
  1. [4,8,10]
  2. [4,8,10]

Array retainAll(Array <srcData>, Array <dataToRetain>)

where:

  • <srcData> is the array from which values are to be removed
  • <dataToRetain> is the array of values to be retained if they also exist in <srcData>

Retains only the elements that exist in both srcData and dataToRetain.

  1. #data.retainAll(new int[] {2,4,6,8,10}, new int[] {2,6,11})
  2. #data.retainAll({2,4,6,8,10}, new int[] {2,6,11})
  1. [2,6]
  2. [2,6]

Array union(Array <array1>, Array <array2>)

where:

  • <array1> is the first array to which elements will be added to
  • <array2> is the second array whose elements will be appended to first array.

Returns a new array containing the second array appended to the first array.

  1. #data.union(new int[] {2,4,6,8,10}, new int[] {1,10,11})
  2. #data.union(new int[] {2,4,6,8,10}, {1,10,11})
  1. [2,4,6,8,10,1,10,11]
  2. [2,4,6,8,10,1,10,11]

int size(Array <inputArray>)

where <inputArray> is the array for which the size is determined.

Returns the size of the input array.

  1. #data.size(new int[] {2,4,6,8,10})
  2. #data.size({2,4,6,8,10})
  1. 5
  2. 5

boolean equals(Array <array1>, Array <array2>)

where <array1> is the first array which is compared against <array2>.

Tests two arrays for value-equality and returns true if both arrays have the same size and all corresponding pairs of elements in the two arrays are equal.

  1. #data.equals(new int[] {2,4,6,8,10}, new int[] {2,4,6,8,10})
  2. #data.equals({2,4,6,8,10}, new int[] {2,4,6,8,10})
  1. true
  2. true