java.lang.Object
ushiosan.jvm_utilities.internal.collection.ArrsImpl

public final class ArrsImpl extends Object
  • Method Details

    • toNumberArray

      public static Number @NotNull [] toNumberArray(@NotNull @NotNull Object array)
      Convert any array of primitive numbers to an array of numeric objects
      Parameters:
      array - the array to convert
      Returns:
      an array with all numeric objects
      Throws:
      IllegalArgumentException - Error if the array is not valid
    • toObjectArray

      public static Object @NotNull [] toObjectArray(@NotNull @NotNull 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[]) ArraysImpl.toObjectArray(new int[] {2, 4, 6, 8});
       Number[] shortArr = (Number[]) ArraysImpl.toObjectArray(new short[] {12, 21, 42, 120, 0xFF});
       Number[] floatArr = (Number[]) ArraysImpl.toObjectArray(new float[] {1f, 2f, 3f, 120.2234f});
       // Wrapped clases
       Boolean[] boolArr = (Boolean[]) ArraysImpl.toObjectArray(new boolean[] {true, false, false, true});
       Character[] intArr = (Character[]) ArraysImpl.toObjectArray(new char[] {'H', 'e', 'l', 'l', 'o'});
       
      Parameters:
      array - the array to convert
      Returns:
      a converted array object