Class ArrayUtils


  • public final class ArrayUtils
    extends java.lang.Object
    Array utils for stuff that isn't included in Arrays.
    Author:
    thomas.jungblut
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double[] concat​(double[]... arrays)
      Concats the given arrays.
      static int[] concat​(int[]... arrays)
      Concats the given arrays.
      static long[] concat​(long[]... arrays)
      Concats the given arrays.
      static <T> T[] concat​(T[]... arrays)
      Concats the given arrays.
      static double[] copy​(double[] array)
      Copies the given array into a new one.
      static int[] copy​(int[] array)
      Copies the given array into a new one.
      static long[] copy​(long[] array)
      Copies the given array into a new one.
      static <T> T[] copy​(T[] array)
      Copies the given array into a new one.
      static void countingSort​(int[] a, int low, int high)
      Counting sort that sorts the integer array in O(n+k) where n is the number of elements and k is the length of the integer intervals given (high - low).
      static byte[] create​(byte... arrays)
      Creates the given array from a varargs parameter.
      static double[] create​(double... arrays)
      Creates the given array from a varargs parameter.
      static int[] create​(int... arrays)
      Creates the given array from a varargs parameter.
      static long[] create​(long... arrays)
      Creates the given array from a varargs parameter.
      static <T> T[] create​(T... arrays)
      Creates the given array from a varargs parameter.
      static int[] deduplicate​(int[] arr)
      Deduplicates an array in linear time, it does not change the order of the elements.
      static <T> java.util.ArrayList<T> deduplicate​(T[] arr)
      Deduplicates an array in linear time, it does not change the order of the elements.
      static int find​(int[] array, int key)
      Finds the occurence of the given key in the given array.
      static int find​(long[] array, long key)
      Finds the occurence of the given key in the given array.
      static <T> int find​(T[] array, T key)
      Finds the occurence of the given key in the given array.
      static double[] fromUpTo​(double from, double to, double stepsize)
      Creates a double array from the given start up to a end number with a stepsize.
      static int[] fromUpTo​(int from, int to, int stepsize)
      Creates an integer array from the given start up to a end number with a stepsize.
      static long[] fromUpTo​(long from, long to, long stepsize)
      Creates a long array from the given start up to a end number with a stepsize.
      static int[] intersection​(int[] arr, int[] arr2)
      Computes the intersection of two sorted arrays.
      static int[] intersectionUnsorted​(int[] arr, int[] arr2)
      Computes the intersection of two unsorted arrays.
      static boolean isValidIndex​(boolean[] array, int index)  
      static boolean isValidIndex​(byte[] array, int index)  
      static boolean isValidIndex​(double[] array, int index)  
      static boolean isValidIndex​(float[] array, int index)  
      static boolean isValidIndex​(int[] array, int index)  
      static boolean isValidIndex​(long[] array, int index)  
      static <T> boolean isValidIndex​(T[] array, int index)  
      static double max​(double[] array)  
      static int max​(int[] array)  
      static long max​(long[] array)  
      static int maxIndex​(double[] array)  
      static int maxIndex​(int[] array)  
      static int maxIndex​(long[] array)  
      static int medianOfMedians​(int[] array)
      Finds the median of medians in the given array.
      static int[] merge​(int[] a, int[] b)
      Merges two sorted arrays to a single new array.
      static void merge​(int[] numbers, int startIndexA, int endIndexA, int endIndexB)
      Merges two sorted subparts of the given number array.
      static double min​(double[] array)  
      static int min​(int[] array)  
      static long min​(long[] array)  
      static int minIndex​(double[] array)  
      static int minIndex​(int[] array)  
      static int minIndex​(long[] array)  
      static int missingNumber​(int[] array)
      If array contains unique integers in a range between 0 and n-1, this function finds the only one missing in linear time and constant memory.
      static void multiQuickSort​(int[]... arrays)
      Multi-sorts the given arrays with the quicksort algorithm.
      static void multiQuickSort​(int sortDimension, int[]... arrays)
      Multi-sorts the given arrays with the quicksort algorithm.
      static <T extends java.lang.Comparable<T>>
      void
      multiQuickSort​(int sortDimension, T[]... arrays)
      Multi-sorts the given arrays with the quicksort algorithm.
      static <T extends java.lang.Comparable<T>>
      void
      multiQuickSort​(T[]... arrays)
      Multi-sorts the given arrays with the quicksort algorithm.
      static <T> T[] multiShuffle​(T[] array, java.util.Random rnd, T[]... additions)
      Shuffles the given array with the given random function.
      static <T> T[] multiShuffle​(T[] array, T[]... additions)
      Shuffles the given array.
      static int partition​(double[] array)
      Partitions the given array in-place and uses the last element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot.
      static int partition​(double[] array, int start, int end)
      Partitions the given array in-place and uses the end element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot.
      static int partition​(int[] array)
      Partitions the given array in-place and uses the last element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot.
      static int partition​(int[] array, int start, int end)
      Partitions the given array in-place and uses the end element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot.
      static int partition​(long[] array)
      Partitions the given array in-place and uses the last element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot.
      static int partition​(long[] array, int start, int end)
      Partitions the given array in-place and uses the end element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot.
      static <T extends java.lang.Comparable<T>>
      int
      partition​(T[] array)
      Partitions the given array in-place and uses the last element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot.
      static <T extends java.lang.Comparable<T>>
      int
      partition​(T[] array, int start, int end)
      Partitions the given array in-place and uses the end element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot.
      static int quickSelect​(double[] array, int k)
      Selects the kth smallest element in the array in linear time.
      static int quickSelect​(double[] array, int start, int end, int k)
      Selects the kth smallest element in the array.
      static int quickSelect​(int[] array, int k)
      Selects the kth smallest element in the array in linear time, if the array is smaller than or equal to 10 a radix sort will be used and the kth element will be returned.
      static int quickSelect​(int[] array, int start, int end, int k)
      Selects the kth smallest element in the array.
      static int quickSelect​(long[] array, int k)
      Selects the kth smallest element in the array in linear time.
      static int quickSelect​(long[] array, int start, int end, int k)
      Selects the kth smallest element in the array.
      static <T extends java.lang.Comparable<T>>
      int
      quickSelect​(T[] array, int k)
      Selects the kth smallest element in the array in linear time.
      static <T extends java.lang.Comparable<T>>
      int
      quickSelect​(T[] array, int start, int end, int k)
      Selects the kth smallest element in the array.
      static void quickSort​(double[] a)
      Quicksorts this array.
      static void quickSort​(double[] a, int offset, int length)
      Quicksorts this array.
      static void quickSort​(int[] a)
      Quicksorts this array.
      static void quickSort​(int[] a, int offset, int length)
      Quicksorts this array.
      static void quickSort​(long[] a)
      Quicksorts this array.
      static void quickSort​(long[] a, int offset, int length)
      Quicksorts this array.
      static <T extends java.lang.Comparable<T>>
      void
      quickSort​(T[] a)
      Quicksorts this array.
      static <T extends java.lang.Comparable<T>>
      void
      quickSort​(T[] a, int offset, int length)
      Quicksorts this array.
      static void radixSort​(int[] a)
      Radix sorts an integer array in O(m*n), where m is the length of the key (here 32 bit) and n the number of elements.
      static <T> T[] shuffle​(T[] array)
      Shuffles the given array.
      static <T> T[] shuffle​(T[] array, java.util.Random rnd)
      Shuffles the given array with the given random function.
      static <T> T[] subArray​(T[] array, int splitIndex)
      Splits the given array from 0 to the given splitindex (included).
      static <T> T[] subArray​(T[] array, int startIndex, int splitIndex)
      Splits the given array from the given startIndex to the given splitIndex (included).
      static void swap​(boolean[] array, int x, int y)
      Swaps the given index x with y in the array.
      static void swap​(double[] array, int x, int y)
      Swaps the given index x with y in the array.
      static void swap​(int[] array, int x, int y)
      Swaps the given index x with y in the array.
      static void swap​(long[] array, int x, int y)
      Swaps the given index x with y in the array.
      static <T> void swap​(T[] array, int x, int y)
      Swaps the given index x with y in the array.
      static java.util.List<java.lang.Double> toObjectList​(double[] array)
      Converts the given double array to a list of object wrappers.
      static java.util.List<java.lang.Integer> toObjectList​(int[] array)
      Converts the given int array to a list of object wrappers.
      static java.util.List<java.lang.Long> toObjectList​(long[] array)
      Converts the given long array to a list of object wrappers.
      static double[] toPrimitiveArray​(java.lang.Double[] array)
      Converts the given array of object type to its primitive counterpart.
      static int[] toPrimitiveArray​(java.lang.Integer[] array)
      Converts the given array of object type to its primitive counterpart.
      static long[] toPrimitiveArray​(java.lang.Long[] array)
      Converts the given array of object type to its primitive counterpart.
      static int[] toPrimitiveArray​(java.util.List<java.lang.Integer> list)
      Converts the given list of object type to its primitive counterpart.
      static int[] union​(int[] a, int[] b)
      Computes the union of two arrays.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • find

        public static <T> int find​(T[] array,
                                   T key)
        Finds the occurence of the given key in the given array. Linear search, worst case running time is O(n).
        Parameters:
        array - the array to search.
        key - the key to search.
        Returns:
        -1 if the key wasn't found nowhere, or the index where the key was found.
      • find

        public static int find​(int[] array,
                               int key)
        Finds the occurence of the given key in the given array. Linear search, worst case running time is O(n).
        Parameters:
        array - the array to search.
        key - the key to search.
        Returns:
        -1 if the key wasn't found nowhere, or the index where the key was found.
      • find

        public static int find​(long[] array,
                               long key)
        Finds the occurence of the given key in the given array. Linear search, worst case running time is O(n).
        Parameters:
        array - the array to search.
        key - the key to search.
        Returns:
        -1 if the key wasn't found nowhere, or the index where the key was found.
      • concat

        public static int[] concat​(int[]... arrays)
        Concats the given arrays.
        Parameters:
        arrays - the arrays to pass.
        Returns:
        a single array where the given arrays content is concatenated.
      • concat

        public static long[] concat​(long[]... arrays)
        Concats the given arrays.
        Parameters:
        arrays - the arrays to pass.
        Returns:
        a single array where the given arrays content is concatenated.
      • concat

        public static double[] concat​(double[]... arrays)
        Concats the given arrays.
        Parameters:
        arrays - the arrays to pass.
        Returns:
        a single array where the given arrays content is concatenated.
      • concat

        public static <T> T[] concat​(T[]... arrays)
        Concats the given arrays.
        Parameters:
        arrays - the arrays to pass.
        Returns:
        a single array where the given arrays content is concatenated.
      • copy

        public static int[] copy​(int[] array)
        Copies the given array into a new one.
      • copy

        public static double[] copy​(double[] array)
        Copies the given array into a new one.
      • copy

        public static long[] copy​(long[] array)
        Copies the given array into a new one.
      • copy

        public static <T> T[] copy​(T[] array)
        Copies the given array into a new one.
      • swap

        public static void swap​(int[] array,
                                int x,
                                int y)
        Swaps the given index x with y in the array.
      • swap

        public static void swap​(long[] array,
                                int x,
                                int y)
        Swaps the given index x with y in the array.
      • swap

        public static void swap​(double[] array,
                                int x,
                                int y)
        Swaps the given index x with y in the array.
      • swap

        public static void swap​(boolean[] array,
                                int x,
                                int y)
        Swaps the given index x with y in the array.
      • swap

        public static <T> void swap​(T[] array,
                                    int x,
                                    int y)
        Swaps the given index x with y in the array.
      • toPrimitiveArray

        public static int[] toPrimitiveArray​(java.util.List<java.lang.Integer> list)
        Converts the given list of object type to its primitive counterpart.
      • toPrimitiveArray

        public static int[] toPrimitiveArray​(java.lang.Integer[] array)
        Converts the given array of object type to its primitive counterpart.
      • toPrimitiveArray

        public static long[] toPrimitiveArray​(java.lang.Long[] array)
        Converts the given array of object type to its primitive counterpart.
      • toPrimitiveArray

        public static double[] toPrimitiveArray​(java.lang.Double[] array)
        Converts the given array of object type to its primitive counterpart.
      • toObjectList

        public static java.util.List<java.lang.Integer> toObjectList​(int[] array)
        Converts the given int array to a list of object wrappers.
      • toObjectList

        public static java.util.List<java.lang.Long> toObjectList​(long[] array)
        Converts the given long array to a list of object wrappers.
      • toObjectList

        public static java.util.List<java.lang.Double> toObjectList​(double[] array)
        Converts the given double array to a list of object wrappers.
      • partition

        public static <T extends java.lang.Comparable<T>> int partition​(T[] array)
        Partitions the given array in-place and uses the last element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot. It returns the index of the pivot element after partitioning.
      • partition

        public static <T extends java.lang.Comparable<T>> int partition​(T[] array,
                                                                        int start,
                                                                        int end)
        Partitions the given array in-place and uses the end element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot. It returns the index of the pivot element after partitioning.
      • partition

        public static int partition​(int[] array)
        Partitions the given array in-place and uses the last element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot. It returns the index of the pivot element after partitioning.
      • partition

        public static int partition​(int[] array,
                                    int start,
                                    int end)
        Partitions the given array in-place and uses the end element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot. It returns the index of the pivot element after partitioning.
      • partition

        public static int partition​(long[] array)
        Partitions the given array in-place and uses the last element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot. It returns the index of the pivot element after partitioning.
      • partition

        public static int partition​(long[] array,
                                    int start,
                                    int end)
        Partitions the given array in-place and uses the end element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot. It returns the index of the pivot element after partitioning.
      • partition

        public static int partition​(double[] array)
        Partitions the given array in-place and uses the last element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot. It returns the index of the pivot element after partitioning.
      • partition

        public static int partition​(double[] array,
                                    int start,
                                    int end)
        Partitions the given array in-place and uses the end element as pivot, everything less than the pivot will be placed left and everything greater will be placed right of the pivot. It returns the index of the pivot element after partitioning.
      • quickSelect

        public static int quickSelect​(int[] array,
                                      int k)
        Selects the kth smallest element in the array in linear time, if the array is smaller than or equal to 10 a radix sort will be used and the kth element will be returned. So k = 1, will return the absolutely smallest element.
        Returns:
        the kth smallest index of the element.
      • quickSelect

        public static int quickSelect​(int[] array,
                                      int start,
                                      int end,
                                      int k)
        Selects the kth smallest element in the array.
        Parameters:
        start - the index where to start.
        end - the index where to end.
        Returns:
        the kth smallest index of the element.
      • quickSelect

        public static int quickSelect​(double[] array,
                                      int k)
        Selects the kth smallest element in the array in linear time. k = 1, will return the absolutely smallest element.
        Returns:
        the kth smallest index of the element.
      • quickSelect

        public static int quickSelect​(double[] array,
                                      int start,
                                      int end,
                                      int k)
        Selects the kth smallest element in the array.
        Parameters:
        start - the index where to start.
        end - the index where to end.
        Returns:
        the kth smallest index of the element.
      • quickSelect

        public static int quickSelect​(long[] array,
                                      int k)
        Selects the kth smallest element in the array in linear time. k = 1, will return the absolutely smallest element.
        Returns:
        the kth smallest index of the element.
      • quickSelect

        public static int quickSelect​(long[] array,
                                      int start,
                                      int end,
                                      int k)
        Selects the kth smallest element in the array.
        Parameters:
        start - the index where to start.
        end - the index where to end.
        Returns:
        the kth smallest index of the element.
      • quickSelect

        public static <T extends java.lang.Comparable<T>> int quickSelect​(T[] array,
                                                                          int k)
        Selects the kth smallest element in the array in linear time. k = 1, will return the absolutely smallest element.
        Returns:
        the kth smallest index of the element.
      • quickSelect

        public static <T extends java.lang.Comparable<T>> int quickSelect​(T[] array,
                                                                          int start,
                                                                          int end,
                                                                          int k)
        Selects the kth smallest element in the array.
        Parameters:
        start - the index where to start.
        end - the index where to end.
        Returns:
        the kth smallest index of the element.
      • medianOfMedians

        public static int medianOfMedians​(int[] array)
        Finds the median of medians in the given array.
        Returns:
        the index of the median of medians.
      • fromUpTo

        public static int[] fromUpTo​(int from,
                                     int to,
                                     int stepsize)
        Creates an integer array from the given start up to a end number with a stepsize.
        Parameters:
        from - the integer to start with.
        to - the integer to end with.
        stepsize - the stepsize to take
        Returns:
        an integer array from start to end incremented by stepsize.
      • fromUpTo

        public static long[] fromUpTo​(long from,
                                      long to,
                                      long stepsize)
        Creates a long array from the given start up to a end number with a stepsize.
        Parameters:
        from - the long to start with.
        to - the long to end with.
        stepsize - the stepsize to take
        Returns:
        a long array from start to end incremented by stepsize.
      • fromUpTo

        public static double[] fromUpTo​(double from,
                                        double to,
                                        double stepsize)
        Creates a double array from the given start up to a end number with a stepsize.
        Parameters:
        from - the double to start with.
        to - the double to end with.
        stepsize - the stepsize to take
        Returns:
        a double array from start to end incremented by stepsize.
      • radixSort

        public static void radixSort​(int[] a)
        Radix sorts an integer array in O(m*n), where m is the length of the key (here 32 bit) and n the number of elements. It only works for positive numbers, so please don't come up with negative numbers, it will result in array out of bound exceptions, since they don't have an array index.
      • countingSort

        public static void countingSort​(int[] a,
                                        int low,
                                        int high)
        Counting sort that sorts the integer array in O(n+k) where n is the number of elements and k is the length of the integer intervals given (high - low). So you can imagine that it uses domain knowledge of the contained integers, like the lowest value and the highest. It only works for positive numbers, so please don't come up with negative numbers, it will result in array out of bound exceptions, since they don't have an array index.
      • quickSort

        public static void quickSort​(int[] a)
        Quicksorts this array.
      • quickSort

        public static void quickSort​(int[] a,
                                     int offset,
                                     int length)
        Quicksorts this array. With offset and length, this will be recursively called by itself.
      • quickSort

        public static void quickSort​(long[] a)
        Quicksorts this array.
      • quickSort

        public static void quickSort​(long[] a,
                                     int offset,
                                     int length)
        Quicksorts this array. With offset and length, this will be recursively called by itself.
      • quickSort

        public static void quickSort​(double[] a)
        Quicksorts this array.
      • quickSort

        public static void quickSort​(double[] a,
                                     int offset,
                                     int length)
        Quicksorts this array. With offset and length, this will be recursively called by itself.
      • quickSort

        public static <T extends java.lang.Comparable<T>> void quickSort​(T[] a)
        Quicksorts this array.
      • quickSort

        public static <T extends java.lang.Comparable<T>> void quickSort​(T[] a,
                                                                         int offset,
                                                                         int length)
        Quicksorts this array. With offset and length, this will be recursively called by itself.
      • multiQuickSort

        public static void multiQuickSort​(int[]... arrays)
        Multi-sorts the given arrays with the quicksort algorithm. It assumes that all arrays have the same sizes and it sorts on the first dimension of these arrays. If the given arrays are null or empty, it will do nothing, if just a single array was passed it will sort it via Arrays sort;
      • multiQuickSort

        public static void multiQuickSort​(int sortDimension,
                                          int[]... arrays)
        Multi-sorts the given arrays with the quicksort algorithm. It assumes that all arrays have the same sizes and it sorts on the given dimension index (starts with 0) of these arrays. If the given arrays are null or empty, it will do nothing, if just a single array was passed it will sort it via Arrays sort;
      • multiQuickSort

        @SafeVarargs
        public static <T extends java.lang.Comparable<T>> void multiQuickSort​(T[]... arrays)
        Multi-sorts the given arrays with the quicksort algorithm. It assumes that all arrays have the same sizes and it sorts on the first dimension of these arrays. If the given arrays are null or empty, it will do nothing, if just a single array was passed it will sort it via Arrays sort;
      • multiQuickSort

        @SafeVarargs
        public static <T extends java.lang.Comparable<T>> void multiQuickSort​(int sortDimension,
                                                                              T[]... arrays)
        Multi-sorts the given arrays with the quicksort algorithm. It assumes that all arrays have the same sizes and it sorts on the given dimension index (starts with 0) of these arrays. If the given arrays are null or empty, it will do nothing, if just a single array was passed it will sort it via Arrays sort;
      • deduplicate

        public static int[] deduplicate​(int[] arr)
        Deduplicates an array in linear time, it does not change the order of the elements.
      • deduplicate

        public static <T> java.util.ArrayList<T> deduplicate​(T[] arr)
        Deduplicates an array in linear time, it does not change the order of the elements. Note that equals and hashcode must be overridden for this to work.
      • union

        public static int[] union​(int[] a,
                                  int[] b)
        Computes the union of two arrays.
      • intersection

        public static int[] intersection​(int[] arr,
                                         int[] arr2)
        Computes the intersection of two sorted arrays. Will deduplicate the items, so the return is a set of integers.
      • intersectionUnsorted

        public static int[] intersectionUnsorted​(int[] arr,
                                                 int[] arr2)
        Computes the intersection of two unsorted arrays. Will deduplicate the items, so the return is a set of integers.
      • missingNumber

        public static int missingNumber​(int[] array)
        If array contains unique integers in a range between 0 and n-1, this function finds the only one missing in linear time and constant memory. This is more of a typical homework or interview question than of actually use.
        The trick is to sum the items in the array and then calculate the expected sum of the elements, then diff and return the value.
      • min

        public static int min​(int[] array)
        Returns:
        the min value in this array,
      • minIndex

        public static int minIndex​(int[] array)
        Returns:
        the minimum index in this array,
      • min

        public static long min​(long[] array)
        Returns:
        the minimum value in this array,
      • minIndex

        public static int minIndex​(long[] array)
        Returns:
        the minimum index in this array,
      • min

        public static double min​(double[] array)
        Returns:
        the minimum value in this array,
      • minIndex

        public static int minIndex​(double[] array)
        Returns:
        the minimum index in this array,
      • max

        public static int max​(int[] array)
        Returns:
        the maximum value in this array,
      • maxIndex

        public static int maxIndex​(int[] array)
        Returns:
        the maximum index in this array,
      • max

        public static long max​(long[] array)
        Returns:
        the maximum value in this array,
      • maxIndex

        public static int maxIndex​(long[] array)
        Returns:
        the maximum index in this array,
      • max

        public static double max​(double[] array)
        Returns:
        the maximum value in this array,
      • maxIndex

        public static int maxIndex​(double[] array)
        Returns:
        the maximum index in this array,
      • subArray

        public static <T> T[] subArray​(T[] array,
                                       int splitIndex)
        Splits the given array from 0 to the given splitindex (included).
        Returns:
        a new array with the same objects in array[0..splitIndex]
      • subArray

        public static <T> T[] subArray​(T[] array,
                                       int startIndex,
                                       int splitIndex)
        Splits the given array from the given startIndex to the given splitIndex (included).
        Returns:
        a new array with the same objects in array[startIndex..splitIndex]
      • shuffle

        public static <T> T[] shuffle​(T[] array)
        Shuffles the given array.
        Returns:
        mutated parameter array that was shuffled beforehand.
      • shuffle

        public static <T> T[] shuffle​(T[] array,
                                      java.util.Random rnd)
        Shuffles the given array with the given random function.
        Returns:
        mutated parameter array that was shuffled beforehand.
      • multiShuffle

        @SafeVarargs
        public static <T> T[] multiShuffle​(T[] array,
                                           T[]... additions)
        Shuffles the given array.
        Returns:
        mutated parameter array that was shuffled beforehand.
      • multiShuffle

        @SafeVarargs
        public static <T> T[] multiShuffle​(T[] array,
                                           java.util.Random rnd,
                                           T[]... additions)
        Shuffles the given array with the given random function.
        Returns:
        mutated parameter array that was shuffled beforehand.
      • create

        public static int[] create​(int... arrays)
        Creates the given array from a varargs parameter.
        Parameters:
        arrays - the array to create.
        Returns:
        the inputted stuff as array.
      • create

        public static long[] create​(long... arrays)
        Creates the given array from a varargs parameter.
        Parameters:
        arrays - the array to create.
        Returns:
        the inputted stuff as array.
      • create

        public static double[] create​(double... arrays)
        Creates the given array from a varargs parameter.
        Parameters:
        arrays - the array to create.
        Returns:
        the inputted stuff as array.
      • create

        public static byte[] create​(byte... arrays)
        Creates the given array from a varargs parameter.
        Parameters:
        arrays - the array to create.
        Returns:
        the inputted stuff as array.
      • create

        @SafeVarargs
        public static <T> T[] create​(T... arrays)
        Creates the given array from a varargs parameter.
        Parameters:
        arrays - the array to create.
        Returns:
        the inputted stuff as array.
      • merge

        public static int[] merge​(int[] a,
                                  int[] b)
        Merges two sorted arrays to a single new array.
        Parameters:
        a - sorted array.
        b - sorted array.
        Returns:
        a new array that merged both into a new sorted array.
      • merge

        public static void merge​(int[] numbers,
                                 int startIndexA,
                                 int endIndexA,
                                 int endIndexB)
        Merges two sorted subparts of the given number array. E.G: if you want to merge { 1, 2, 5, 3, 5, 6, 7 } you have to pass merge(concat, 0, 2, 6), because you are starting at zero, the second sorted array begins at index 3, so it is 3-1=2. The end is the length of the array - 1.
        Parameters:
        numbers - the array which has two sorted sub arrays.
        startIndexA - the start index of the first sorted array.
        endIndexA - the end index of the first sorted array.
        endIndexB - the end of the second array.
      • isValidIndex

        public static boolean isValidIndex​(int[] array,
                                           int index)
        Returns:
        true if the given index is inside the array range between 0 and array.length (exclusive).
      • isValidIndex

        public static boolean isValidIndex​(double[] array,
                                           int index)
        Returns:
        true if the given index is inside the array range between 0 and array.length (exclusive).
      • isValidIndex

        public static boolean isValidIndex​(float[] array,
                                           int index)
        Returns:
        true if the given index is inside the array range between 0 and array.length (exclusive).
      • isValidIndex

        public static boolean isValidIndex​(long[] array,
                                           int index)
        Returns:
        true if the given index is inside the array range between 0 and array.length (exclusive).
      • isValidIndex

        public static boolean isValidIndex​(boolean[] array,
                                           int index)
        Returns:
        true if the given index is inside the array range between 0 and array.length (exclusive).
      • isValidIndex

        public static boolean isValidIndex​(byte[] array,
                                           int index)
        Returns:
        true if the given index is inside the array range between 0 and array.length (exclusive).
      • isValidIndex

        public static <T> boolean isValidIndex​(T[] array,
                                               int index)
        Returns:
        true if the given index is inside the array range between 0 and array.length (exclusive).