info.jonclark.util
Class ArrayUtils

java.lang.Object
  extended by info.jonclark.util.ArrayUtils

public class ArrayUtils
extends Object

Utilities for working with arrays


Constructor Summary
ArrayUtils()
           
 
Method Summary
static
<T> String
arrayToString(boolean[] arr)
          Convert an array into a string of the form {element1, element2, element3...
static
<T> String
arrayToString(double[] arr)
          Convert an array into a string of the form {element1, element2, element3...
static
<T> String
arrayToString(float[] arr)
          Convert an array into a string of the form {element1, element2, element3...
static
<T> String
arrayToString(int[] arr)
          Convert an array into a string of the form {element1, element2, element3...
static
<T> String
arrayToString(long[] arr)
          Convert an array into a string of the form {element1, element2, element3...
static
<T> String
arrayToString(T[] arr)
          Convert an array into a string of the form {element1, element2, element3...
static
<T> Vector<T>
arrayToVector(T[] arr)
          (Somewhat) efficiently convert an array into a vector (requires a full copy of the array to the vector).
static boolean sortedArrayContains(int[] arr, int key)
          Find out if a sorted array contains a value
static boolean unsortedArrayContains(int[] arr, int key)
          Find out if an unsorted array contains a value
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayUtils

public ArrayUtils()
Method Detail

arrayToString

public static <T> String arrayToString(T[] arr)
Convert an array into a string of the form {element1, element2, element3... }

Type Parameters:
T - The type of the array
Parameters:
arr - The array to be converted into string form
Returns:
A string representation of the array

arrayToString

public static <T> String arrayToString(int[] arr)
Convert an array into a string of the form {element1, element2, element3... }

Type Parameters:
T - The type of the array
Parameters:
arr - The array to be converted into string form
Returns:
A string representation of the array

arrayToString

public static <T> String arrayToString(long[] arr)
Convert an array into a string of the form {element1, element2, element3... }

Type Parameters:
T - The type of the array
Parameters:
arr - The array to be converted into string form
Returns:
A string representation of the array

arrayToString

public static <T> String arrayToString(float[] arr)
Convert an array into a string of the form {element1, element2, element3... }

Type Parameters:
T - The type of the array
Parameters:
arr - The array to be converted into string form
Returns:
A string representation of the array

arrayToString

public static <T> String arrayToString(double[] arr)
Convert an array into a string of the form {element1, element2, element3... }

Type Parameters:
T - The type of the array
Parameters:
arr - The array to be converted into string form
Returns:
A string representation of the array

arrayToString

public static <T> String arrayToString(boolean[] arr)
Convert an array into a string of the form {element1, element2, element3... }

Type Parameters:
T - The type of the array
Parameters:
arr - The array to be converted into string form
Returns:
A string representation of the array

arrayToVector

public static <T> Vector<T> arrayToVector(T[] arr)
(Somewhat) efficiently convert an array into a vector (requires a full copy of the array to the vector).

Parameters:
arr - The array to be converted into a vector
Returns:
A vector containing all the elements of arr

sortedArrayContains

public static boolean sortedArrayContains(int[] arr,
                                          int key)
Find out if a sorted array contains a value

Parameters:
arr - The array to be searched
key - The value to find in the array
Returns:
True if the value is found in the array

unsortedArrayContains

public static boolean unsortedArrayContains(int[] arr,
                                            int key)
Find out if an unsorted array contains a value

Parameters:
arr - The array to be searched
key - The value to find in the array
Returns:
True if the value is found in the array