Class ArrayUtils

java.lang.Object
org.apache.commons.collections4.ArrayUtils

final class ArrayUtils extends Object

Operations on arrays, primitive arrays (like int[]) and primitive wrapper arrays (like Integer[]).

This class tries to handle null input gracefully. An exception will not be thrown for a null array input. However, an Object array that contains a null element may throw an exception. Each method documents its behavior.

Package private, might move to an internal package if this needs to be public.

#ThreadSafe#

Since:
4.2 (Copied from Apache Commons Lang.)
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Don't allow instances.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static boolean
    contains(Object[] array, Object objectToFind)
    Checks if the object is in the given array.
    (package private) static int
    indexOf(Object[] array, Object objectToFind, int startIndex)
    Finds the index of the given object in the array starting at the given index.
    (package private) static <T> int
    indexOf(T[] array, Object objectToFind)
    Finds the index of the given object in the array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ArrayUtils

      private ArrayUtils()
      Don't allow instances.
  • Method Details

    • contains

      static boolean contains(Object[] array, Object objectToFind)

      Checks if the object is in the given array.

      The method returns false if a null array is passed in.

      Parameters:
      array - the array to search, may be null.
      objectToFind - the object to find, may be null.
      Returns:
      true if the array contains the object
    • indexOf

      static int indexOf(Object[] array, Object objectToFind, int startIndex)

      Finds the index of the given object in the array starting at the given index.

      This method returns CollectionUtils.INDEX_NOT_FOUND (-1) for a null input array.

      A negative startIndex is treated as zero. A startIndex larger than the array length will return CollectionUtils.INDEX_NOT_FOUND (-1).

      Parameters:
      array - the array to search for the object, may be null.
      objectToFind - the object to find, may be null.
      startIndex - the index to start searching at
      Returns:
      the index of the object within the array starting at the index, CollectionUtils.INDEX_NOT_FOUND (-1) if not found or null array input
    • indexOf

      static <T> int indexOf(T[] array, Object objectToFind)

      Finds the index of the given object in the array.

      This method returns CollectionUtils.INDEX_NOT_FOUND (-1) for a null input array.

      Parameters:
      array - the array to search for the object, may be null.
      objectToFind - the object to find, may be null.
      Returns:
      the index of the object within the array, CollectionUtils.INDEX_NOT_FOUND (-1) if not found or null array input