nl.knowledgeplaza.util
Class ArrayUtil

java.lang.Object
  extended by nl.knowledgeplaza.util.ArrayUtil

public class ArrayUtil
extends Object

This class contains several Array helper methods.

Version:
$Revision: 1.2 $
Author:
$Author: toeukpap $

Field Summary
static String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Constructor Summary
ArrayUtil()
           
 
Method Summary
static byte[] concat(byte[] a, byte[] b)
          Create a new byte array with holds the contents of a follow by b
static String deepToString(Object[] a)
          Returns a string representation of the "deep contents" of the specified array.
static int indexOf(byte[] haystack, byte[] needle)
          Find a needle in a haystack.
static int indexOf(byte[] haystack, byte[] needle, int startAt)
          Find a needle in a haystack.
static void main(String[] args)
           
static byte[] subarray(byte[] data, int begin, int end)
          Make a subarray.
static String toString(boolean[] a)
          Returns a string representation of the contents of the specified array.
static String toString(byte[] a)
          Returns a string representation of the contents of the specified array.
static String toString(char[] a)
          Returns a string representation of the contents of the specified array.
static String toString(double[] a)
          Returns a string representation of the contents of the specified array.
static String toString(float[] a)
          Returns a string representation of the contents of the specified array.
static String toString(int[] a)
          Returns a string representation of the contents of the specified array.
static String toString(long[] a)
          Returns a string representation of the contents of the specified array.
static String toString(Object[] a)
          Returns a string representation of the contents of the specified array.
static String toString(short[] a)
          Returns a string representation of the contents of the specified array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values
Constructor Detail

ArrayUtil

public ArrayUtil()
Method Detail

indexOf

public static int indexOf(byte[] haystack,
                          byte[] needle)
Find a needle in a haystack.

Parameters:
haystack -
needle -
Returns:
position or -1 if not found

indexOf

public static int indexOf(byte[] haystack,
                          byte[] needle,
                          int startAt)
Find a needle in a haystack.

Parameters:
haystack -
needle -
startAt -
Returns:
position or -1 if not found

subarray

public static byte[] subarray(byte[] data,
                              int begin,
                              int end)
Make a subarray.

Parameters:
data - the array
begin -
end -
Returns:

concat

public static byte[] concat(byte[] a,
                            byte[] b)
Create a new byte array with holds the contents of a follow by b

Parameters:
a -
b -
Returns:

toString

public static String toString(long[] a)
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(long). Returns "null" if a is null.

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a
Since:
1.5

toString

public static String toString(int[] a)
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(int). Returns "null" if a is null.

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a
Since:
1.5

toString

public static String toString(short[] a)
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(short). Returns "null" if a is null.

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a
Since:
1.5

toString

public static String toString(char[] a)
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(char). Returns "null" if a is null.

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a
Since:
1.5

toString

public static String toString(byte[] a)
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(byte). Returns "null" if a is null.

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a
Since:
1.5

toString

public static String toString(boolean[] a)
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(boolean). Returns "null" if a is null.

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a
Since:
1.5

toString

public static String toString(float[] a)
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(float). Returns "null" if a is null.

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a
Since:
1.5

toString

public static String toString(double[] a)
Returns a string representation of the contents of the specified array. The string representation consists of a list of the array's elements, enclosed in square brackets ("{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(double). Returns "null" if a is null.

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a
Since:
1.5

toString

public static String toString(Object[] a)
Returns a string representation of the contents of the specified array. If the array contains other arrays as elements, they are converted to strings by the Object.toString() method inherited from Object, which describes their identities rather than their contents.

The value returned by this method is equal to the value that would be returned by Arrays.asList(a).toString(), unless a is null, in which case "null" is returned.

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a
Since:
1.5
See Also:
deepToString(Object[])

deepToString

public static String deepToString(Object[] a)
Returns a string representation of the "deep contents" of the specified array. If the array contains other arrays as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays to strings.

The string representation consists of a list of the array's elements, enclosed in square brackets ("{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(Object), unless they are themselves arrays.

If an element e is an array of a primitive type, it is converted to a string as by invoking the appropriate overloading of Arrays.toString(e). If an element e is an array of a reference type, it is converted to a string as by invoking this method recursively.

To avoid infinite recursion, if the specified array contains itself as an element, or contains an indirect reference to itself through one or more levels of arrays, the self-reference is converted to the string "{...}". For example, an array containing only a reference to itself would be rendered as "{[...]}".

This method returns "null" if the specified array is null.

Parameters:
a - the array whose string representation to return
Returns:
a string representation of a
Since:
1.5
See Also:
toString(Object[])

main

public static void main(String[] args)


Copyright © 2012 KnowledgePlaza. All Rights Reserved.