Class ArrayUtils


  • public final class ArrayUtils
    extends java.lang.Object
    Static utility methods for arrays (like java.util.Arrays, but more useful).
    Version:
    $Id: ArrayUtils.java,v 1.1 2007/10/22 21:37:40 mccallum Exp $
    Author:
    Charles Sutton
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean[] append​(boolean[] v, boolean elem)
      Returns a new array with a single element appended at the end.
      static double[] append​(double[] a1, double[] a2)
      Returns a new array that is the concatenation of a1 and a2.
      static int[] append​(int[] v, int elem)
      Returns a new array with a single element appended at the end.
      static int[] append​(int[] a1, int[] a2)
      Returns a new array that is the concatenation of a1 and a2.
      static java.lang.Object[] append​(java.lang.Object[] v, java.lang.Object elem)
      Returns a new array with a single element appended at the end.
      static int argmax​(double[] elems)  
      static double count​(int[] sampled, int val)
      Returns the number of times a value occurs in a given array.
      static boolean equals​(boolean[][] m1, boolean[][] m2)  
      static double[] extend​(double[] a, int additional)
      Returns a new array containing all of a, with additional extra space added (zero initialized).
      static int[] extend​(int[] a, int additional)
      Returns a new array containing all of a, with additional extra space added (zero initialized).
      static int indexOf​(int[] array, int obj)  
      static int indexOf​(java.lang.Object[] array, java.lang.Object obj)  
      static void print​(double[] v)  
      static void print​(int[] v)  
      static java.lang.String toString​(double[] v)  
      static java.lang.String toString​(int[] v)  
      static java.lang.String toString​(java.lang.Object[] v)  
      • Methods inherited from class java.lang.Object

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

      • indexOf

        public static int indexOf​(java.lang.Object[] array,
                                  java.lang.Object obj)
      • indexOf

        public static int indexOf​(int[] array,
                                  int obj)
      • print

        public static void print​(double[] v)
      • print

        public static void print​(int[] v)
      • toString

        public static java.lang.String toString​(int[] v)
      • toString

        public static java.lang.String toString​(double[] v)
      • toString

        public static java.lang.String toString​(java.lang.Object[] v)
      • extend

        public static int[] extend​(int[] a,
                                   int additional)
        Returns a new array containing all of a, with additional extra space added (zero initialized).
        Parameters:
        a -
        additional -
        Returns:
      • extend

        public static double[] extend​(double[] a,
                                      int additional)
        Returns a new array containing all of a, with additional extra space added (zero initialized).
        Parameters:
        a -
        additional -
        Returns:
      • append

        public static int[] append​(int[] a1,
                                   int[] a2)
        Returns a new array that is the concatenation of a1 and a2.
        Parameters:
        a1 -
        a2 -
        Returns:
      • append

        public static double[] append​(double[] a1,
                                      double[] a2)
        Returns a new array that is the concatenation of a1 and a2.
        Parameters:
        a1 -
        a2 -
        Returns:
      • append

        public static int[] append​(int[] v,
                                   int elem)
        Returns a new array with a single element appended at the end. Use this sparingly, for it will allocate a new array. You can easily turn a linear-time algorithm to quadratic this way.
        Parameters:
        v - Original array
        elem - Element to add to end
      • append

        public static boolean[] append​(boolean[] v,
                                       boolean elem)
        Returns a new array with a single element appended at the end. Use this sparingly, for it will allocate a new array. You can easily turn a linear-time algorithm to quadratic this way.
        Parameters:
        v - Original array
        elem - Element to add to end
      • append

        public static java.lang.Object[] append​(java.lang.Object[] v,
                                                java.lang.Object elem)
        Returns a new array with a single element appended at the end. Use this sparingly, for it will allocate a new array. You can easily turn a linear-time algorithm to quadratic this way.
        Parameters:
        v - Original array
        elem - Element to add to end
        Returns:
        Array with length v+1 that is (v0,v1,...,vn,elem). Runtime type will be same as he pased-in array.
      • count

        public static double count​(int[] sampled,
                                   int val)
        Returns the number of times a value occurs in a given array.
      • argmax

        public static int argmax​(double[] elems)
      • equals

        public static boolean equals​(boolean[][] m1,
                                     boolean[][] m2)