java.lang.Object
ushiosan.jvm_utilities.lang.collection.Arrs

public final class Arrs extends Object
  • Field Details

    • INDEX_NOT_FOUND

      public static final int INDEX_NOT_FOUND
      number to represent not found operation in the arrays
      See Also:
  • Method Details

    • of

      @SafeVarargs public static <T> T[] of(T... elements)
      Generate array from given values. If you want to use primitive arrays, you must use the classes that encapsulate those types.
      Type Parameters:
      T - element types
      Parameters:
      elements - the elements to add
      Returns:
      an array with all values
      See Also:
    • of

      public static Object @NotNull [] of(Iterator<?> iterator)
      Generate array from given values. If you want to use primitive arrays, you must use the classes that encapsulate those types.
      Parameters:
      iterator - the iterator to convert
      Returns:
      an array with all values
      See Also:
    • indexOf

      @Contract(pure=true) public static int indexOf(Object @NotNull [] array, @Nullable @Nullable Object element)
      Search elements in the array
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • lastIndexOf

      @Contract(pure=true) public static int lastIndexOf(Object @NotNull [] array, @Nullable @Nullable Object element)
      Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • contains

      public static boolean contains(Object @NotNull [] array, @Nullable @Nullable Object element)
      Checks if the array contains the selected element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      true if the element exists or false otherwise
    • toObjectArray

      public static Object @NotNull [] toObjectArray(Object array)
      Convert any array to object array. This also applies to primitive types.

      Be careful with this method because this method uses a trick to convert primitive types to numeric types and does not use wrapper classes. Instead, the Number class is used for any numeric type (except for the char type).

      Examples

      
       // For numeric primitives always use Number class
       Number[] intArr   = (Number[]) Arrays.toObjectArray(new int[] {2, 4, 6, 8});
       Number[] shortArr = (Number[]) Arrays.toObjectArray(new short[] {12, 21, 42, 120, 0xFF});
       Number[] floatArr = (Number[]) Arrays.toObjectArray(new float[] {1f, 2f, 3f, 120.2234f});
       // Wrapped clases
       Boolean[] boolArr  = (Boolean[]) Arrays.toObjectArray(new boolean[] {true, false, false, true});
       Character[] intArr = (Character[]) Arrays.toObjectArray(new char[] {'H', 'e', 'l', 'l', 'o'});
       
      Parameters:
      array - the array to convert
      Returns:
      a converted array object
    • numberOf

      public static Number @NotNull [] numberOf(Number @NotNull ... elements)
      Generates a generic array with numeric objects.
      Parameters:
      elements - numeric elements
      Returns:
      an array with all numeric elements
    • booleanOf

      public static boolean[] booleanOf(boolean... elements)
      Generate a primitive boolean array
      Parameters:
      elements - boolean elements
      Returns:
      an array with all boolean elements
    • charOf

      public static char[] charOf(char... elements)
      Generate a primitive char array
      Parameters:
      elements - char elements
      Returns:
      an array with all char elements
    • indexOf

      @Contract(pure=true) public static int indexOf(char @NotNull [] array, char element)
      Search elements in the array
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • lastIndexOf

      public static int lastIndexOf(char @NotNull [] array, char element)
      Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • contains

      public static boolean contains(char @NotNull [] array, char element)
      Checks if the array contains the selected element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      true if the element exists or false otherwise
    • byteOf

      public static byte @NotNull [] byteOf(Number @NotNull ... elements)
      Generate a primitive byte array
      Parameters:
      elements - byte elements
      Returns:
      an array with all bytes
    • toNumberOf

      public static Number @NotNull [] toNumberOf(byte[] array)
      Convert the primitive byte array to a numeric array
      Parameters:
      array - the array to convert
      Returns:
      an array with all numeric objects
      See Also:
    • indexOf

      @Contract(pure=true) public static int indexOf(byte @NotNull [] array, byte element)
      Search elements in the array
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • lastIndexOf

      public static int lastIndexOf(byte @NotNull [] array, byte element)
      Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • contains

      public static boolean contains(byte @NotNull [] array, byte element)
      Checks if the array contains the selected element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      true if the element exists or false otherwise
    • shortOf

      public static short @NotNull [] shortOf(Number @NotNull ... elements)
      Generate a primitive short array
      Parameters:
      elements - short elements
      Returns:
      an array with all shot elements
    • toNumberOf

      public static Number @NotNull [] toNumberOf(short[] array)
      Convert the primitive short array to a numeric array
      Parameters:
      array - the array to convert
      Returns:
      an array with all numeric objects
      See Also:
    • indexOf

      @Contract(pure=true) public static int indexOf(short @NotNull [] array, short element)
      Search elements in the array
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • lastIndexOf

      public static int lastIndexOf(short @NotNull [] array, short element)
      Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • contains

      public static boolean contains(short @NotNull [] array, short element)
      Checks if the array contains the selected element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      true if the element exists or false otherwise
    • intOf

      public static int[] intOf(int... elements)
      Generate a primitive int array
      Parameters:
      elements - int elements
      Returns:
      an array with all int elements
    • toNumberOf

      public static Number @NotNull [] toNumberOf(int[] array)
      Convert the primitive int array to a numeric array
      Parameters:
      array - the array to convert
      Returns:
      an array with all numeric objects
      See Also:
    • indexOf

      @Contract(pure=true) public static int indexOf(int @NotNull [] array, int element)
      Search elements in the array
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • lastIndexOf

      public static int lastIndexOf(int @NotNull [] array, int element)
      Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • contains

      public static boolean contains(int @NotNull [] array, int element)
      Checks if the array contains the selected element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      true if the element exists or false otherwise
    • longOf

      public static long[] longOf(long... elements)
      Generate a primitive long array
      Parameters:
      elements - long elements
      Returns:
      an array with all long elements
    • toNumberOf

      public static Number @NotNull [] toNumberOf(long[] array)
      Convert the primitive long array to a numeric array
      Parameters:
      array - the array to convert
      Returns:
      an array with all numeric objects
      See Also:
    • indexOf

      @Contract(pure=true) public static int indexOf(long @NotNull [] array, long element)
      Search elements in the array
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • lastIndexOf

      public static int lastIndexOf(long @NotNull [] array, long element)
      Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • contains

      public static boolean contains(long @NotNull [] array, long element)
      Checks if the array contains the selected element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      true if the element exists or false otherwise
    • floatOf

      public static float[] floatOf(float... elements)
      Generate a primitive float array
      Parameters:
      elements - float elements
      Returns:
      an array with all float elements
    • toNumberOf

      public static Number @NotNull [] toNumberOf(float[] array)
      Convert the primitive float array to a numeric array
      Parameters:
      array - the array to convert
      Returns:
      an array with all numeric objects
      See Also:
    • indexOf

      @Contract(pure=true) public static int indexOf(float @NotNull [] array, float element)
      Search elements in the array
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • lastIndexOf

      public static int lastIndexOf(float @NotNull [] array, float element)
      Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • contains

      public static boolean contains(float @NotNull [] array, float element)
      Checks if the array contains the selected element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      true if the element exists or false otherwise
    • doubleOf

      public static double[] doubleOf(double... elements)
      Generate a primitive double array
      Parameters:
      elements - double elements
      Returns:
      an array with double bytes
    • toNumberOf

      public static Number @NotNull [] toNumberOf(double[] array)
      Convert the primitive double array to a numeric array
      Parameters:
      array - the array to convert
      Returns:
      an array with all numeric objects
      See Also:
    • indexOf

      @Contract(pure=true) public static int indexOf(double @NotNull [] array, double element)
      Search elements in the array
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • lastIndexOf

      public static int lastIndexOf(double @NotNull [] array, double element)
      Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      the first index element or -1 if element not exists
    • contains

      public static boolean contains(double @NotNull [] array, double element)
      Checks if the array contains the selected element.
      Parameters:
      array - base array to search
      element - the element to search
      Returns:
      true if the element exists or false otherwise