Arrayspublic class Arrays extends Object {@code Arrays} contains static methods which operate on arrays. |
Constructors Summary |
---|
private Arrays()
/* empty */
|
Methods Summary |
---|
public static java.util.List | asList(T array)Returns a {@code List} of the objects in the specified array. The size of the
{@code List} cannot be modified, i.e. adding and removing are unsupported, but
the elements can be set. Setting an element modifies the underlying
array.
return new ArrayList<T>(array);
| public static int | binarySearch(T[] array, T object, java.util.Comparator comparator)Performs a binary search for the specified element in the specified
ascending sorted array using the {@code Comparator} to compare elements.
Searching in an unsorted array has an undefined result. It's also
undefined which element is found if there are multiple occurrences of the
same element.
if (comparator == null) {
return binarySearch(array, object);
}
int low = 0, mid = 0, high = array.length - 1, result = 0;
while (low <= high) {
mid = (low + high) >> 1;
if ((result = comparator.compare(array[mid], object)) < 0) {
low = mid + 1;
} else if (result == 0) {
return mid;
} else {
high = mid - 1;
}
}
return -mid - (result >= 0 ? 1 : 2);
| public static int | binarySearch(short[] array, short value)Performs a binary search for the specified element in the specified
ascending sorted array. Searching in an unsorted array has an undefined
result. It's also undefined which element is found if there are multiple
occurrences of the same element.
int low = 0, mid = -1, high = array.length - 1;
while (low <= high) {
mid = (low + high) >> 1;
if (value > array[mid]) {
low = mid + 1;
} else if (value == array[mid]) {
return mid;
} else {
high = mid - 1;
}
}
if (mid < 0) {
return -1;
}
return -mid - (value < array[mid] ? 1 : 2);
| public static int | binarySearch(byte[] array, byte value)Performs a binary search for the specified element in the specified
ascending sorted array. Searching in an unsorted array has an undefined
result. It's also undefined which element is found if there are multiple
occurrences of the same element.
int low = 0, mid = -1, high = array.length - 1;
while (low <= high) {
mid = (low + high) >> 1;
if (value > array[mid]) {
low = mid + 1;
} else if (value == array[mid]) {
return mid;
} else {
high = mid - 1;
}
}
if (mid < 0) {
return -1;
}
return -mid - (value < array[mid] ? 1 : 2);
| public static int | binarySearch(char[] array, char value)Performs a binary search for the specified element in the specified
ascending sorted array. Searching in an unsorted array has an undefined
result. It's also undefined which element is found if there are multiple
occurrences of the same element.
int low = 0, mid = -1, high = array.length - 1;
while (low <= high) {
mid = (low + high) >> 1;
if (value > array[mid]) {
low = mid + 1;
} else if (value == array[mid]) {
return mid;
} else {
high = mid - 1;
}
}
if (mid < 0) {
return -1;
}
return -mid - (value < array[mid] ? 1 : 2);
| public static int | binarySearch(double[] array, double value)Performs a binary search for the specified element in the specified
ascending sorted array. Searching in an unsorted array has an undefined
result. It's also undefined which element is found if there are multiple
occurrences of the same element.
long longBits = Double.doubleToLongBits(value);
int low = 0, mid = -1, high = array.length - 1;
while (low <= high) {
mid = (low + high) >> 1;
if (lessThan(array[mid], value)) {
low = mid + 1;
} else if (longBits == Double.doubleToLongBits(array[mid])) {
return mid;
} else {
high = mid - 1;
}
}
if (mid < 0) {
return -1;
}
return -mid - (lessThan(value, array[mid]) ? 1 : 2);
| public static int | binarySearch(float[] array, float value)Performs a binary search for the specified element in the specified
ascending sorted array. Searching in an unsorted array has an undefined
result. It's also undefined which element is found if there are multiple
occurrences of the same element.
int intBits = Float.floatToIntBits(value);
int low = 0, mid = -1, high = array.length - 1;
while (low <= high) {
mid = (low + high) >> 1;
if (lessThan(array[mid], value)) {
low = mid + 1;
} else if (intBits == Float.floatToIntBits(array[mid])) {
return mid;
} else {
high = mid - 1;
}
}
if (mid < 0) {
return -1;
}
return -mid - (lessThan(value, array[mid]) ? 1 : 2);
| public static int | binarySearch(int[] array, int value)Performs a binary search for the specified element in the specified
ascending sorted array. Searching in an unsorted array has an undefined
result. It's also undefined which element is found if there are multiple
occurrences of the same element.
int low = 0, mid = -1, high = array.length - 1;
while (low <= high) {
mid = (low + high) >> 1;
if (value > array[mid]) {
low = mid + 1;
} else if (value == array[mid]) {
return mid;
} else {
high = mid - 1;
}
}
if (mid < 0) {
return -1;
}
return -mid - (value < array[mid] ? 1 : 2);
| public static int | binarySearch(long[] array, long value)Performs a binary search for the specified element in the specified
ascending sorted array. Searching in an unsorted array has an undefined
result. It's also undefined which element is found if there are multiple
occurrences of the same element.
int low = 0, mid = -1, high = array.length - 1;
while (low <= high) {
mid = (low + high) >> 1;
if (value > array[mid]) {
low = mid + 1;
} else if (value == array[mid]) {
return mid;
} else {
high = mid - 1;
}
}
if (mid < 0) {
return -1;
}
return -mid - (value < array[mid] ? 1 : 2);
| public static int | binarySearch(java.lang.Object[] array, java.lang.Object object)Performs a binary search for the specified element in the specified
ascending sorted array. Searching in an unsorted array has an undefined
result. It's also undefined which element is found if there are multiple
occurrences of the same element.
if (array.length == 0) {
return -1;
}
Comparable<Object> key = (Comparable<Object>) object;
int low = 0, mid = 0, high = array.length - 1, result = 0;
while (low <= high) {
mid = (low + high) >> 1;
if ((result = key.compareTo(array[mid])) > 0) {
low = mid + 1;
} else if (result == 0) {
return mid;
} else {
high = mid - 1;
}
}
return -mid - (result <= 0 ? 1 : 2);
| private static void | checkBounds(int arrLength, int start, int end)
if (start > end) {
throw new IllegalArgumentException("fromIndex(" + start //$NON-NLS-1$
+ ") > toIndex(" + end + ")"); //$NON-NLS-1$ //$NON-NLS-2$
}
if (start < 0 || end > arrLength) {
throw new ArrayIndexOutOfBoundsException();
}
| public static boolean | deepEquals(java.lang.Object[] array1, java.lang.Object[] array2)Returns {@code true} if the two given arrays are deeply equal to one another.
Unlike the method {@code equals(Object[] array1, Object[] array2)}, this method
is appropriate for use for nested arrays of arbitrary depth.
Two array references are considered deeply equal if they are both {@code null},
or if they refer to arrays that have the same length and the elements at
each index in the two arrays are equal.
Two {@code null} elements {@code element1} and {@code element2} are possibly deeply equal if any
of the following conditions satisfied:
{@code element1} and {@code element2} are both arrays of object reference types, and
{@code Arrays.deepEquals(element1, element2)} would return {@code true}.
{@code element1} and {@code element2} are arrays of the same primitive type, and the
appropriate overloading of {@code Arrays.equals(element1, element2)} would return
{@code true}.
{@code element1 == element2}
{@code element1.equals(element2)} would return {@code true}.
Note that this definition permits {@code null} elements at any depth.
If either of the given arrays contain themselves as elements, the
behavior of this method is uncertain.
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
Object e1 = array1[i], e2 = array2[i];
if (!deepEqualsElements(e1, e2)) {
return false;
}
}
return true;
| private static boolean | deepEqualsElements(java.lang.Object e1, java.lang.Object e2)
Class<?> cl1, cl2;
if (e1 == e2) {
return true;
}
if (e1 == null || e2 == null) {
return false;
}
cl1 = e1.getClass().getComponentType();
cl2 = e2.getClass().getComponentType();
if (cl1 != cl2) {
return false;
}
if (cl1 == null) {
return e1.equals(e2);
}
/*
* compare as arrays
*/
if (!cl1.isPrimitive()) {
return deepEquals((Object[]) e1, (Object[]) e2);
}
if (cl1.equals(int.class)) {
return equals((int[]) e1, (int[]) e2);
}
if (cl1.equals(char.class)) {
return equals((char[]) e1, (char[]) e2);
}
if (cl1.equals(boolean.class)) {
return equals((boolean[]) e1, (boolean[]) e2);
}
if (cl1.equals(byte.class)) {
return equals((byte[]) e1, (byte[]) e2);
}
if (cl1.equals(long.class)) {
return equals((long[]) e1, (long[]) e2);
}
if (cl1.equals(float.class)) {
return equals((float[]) e1, (float[]) e2);
}
if (cl1.equals(double.class)) {
return equals((double[]) e1, (double[]) e2);
}
return equals((short[]) e1, (short[]) e2);
| public static int | deepHashCode(java.lang.Object[] array)Returns a hash code based on the "deep contents" of the given array. If
the array contains other arrays as its elements, the hash code is based
on their contents not their identities. So it is not acceptable to invoke
this method on an array that contains itself as an element, either
directly or indirectly.
For any two arrays {@code a} and {@code b}, if
{@code Arrays.deepEquals(a, b)} returns {@code true}, it
means that the return value of {@code Arrays.deepHashCode(a)} equals
{@code Arrays.deepHashCode(b)}.
The computation of the value returned by this method is similar to that
of the value returned by {@link List#hashCode()}} invoked on a
{@link List}} containing a sequence of instances representing the
elements of array in the same order. The difference is: If an element e
of array is itself an array, its hash code is computed by calling the
appropriate overloading of {@code Arrays.hashCode(e)} if e is an array of a
primitive type, or by calling {@code Arrays.deepHashCode(e)} recursively if e is
an array of a reference type. The value returned by this method is the
same value as the method {@code Arrays.asList(array).hashCode()}. If the array is
{@code null}, the return value is 0.
if (array == null) {
return 0;
}
int hashCode = 1;
for (Object element : array) {
int elementHashCode = deepHashCodeElement(element);
hashCode = 31 * hashCode + elementHashCode;
}
return hashCode;
| private static int | deepHashCodeElement(java.lang.Object element)
Class<?> cl;
if (element == null) {
return 0;
}
cl = element.getClass().getComponentType();
if (cl == null) {
return element.hashCode();
}
/*
* element is an array
*/
if (!cl.isPrimitive()) {
return deepHashCode((Object[]) element);
}
if (cl.equals(int.class)) {
return hashCode((int[]) element);
}
if (cl.equals(char.class)) {
return hashCode((char[]) element);
}
if (cl.equals(boolean.class)) {
return hashCode((boolean[]) element);
}
if (cl.equals(byte.class)) {
return hashCode((byte[]) element);
}
if (cl.equals(long.class)) {
return hashCode((long[]) element);
}
if (cl.equals(float.class)) {
return hashCode((float[]) element);
}
if (cl.equals(double.class)) {
return hashCode((double[]) element);
}
return hashCode((short[]) element);
| public static java.lang.String | deepToString(java.lang.Object[] array)
Creates a "deep" {@code String} representation of the
{@code Object[]} passed, such that if the array contains other arrays,
the {@code String} representation of those arrays is generated as well.
If any of the elements are primitive arrays, the generation is delegated
to the other {@code toString} methods in this class. If any element
contains a reference to the original array, then it will be represented
as {@code "[...]"}. If an element is an {@code Object[]}, then its
representation is generated by a recursive call to this method. All other
elements are converted via the {@link String#valueOf(Object)} method.
// delegate this to the recursive method
return deepToStringImpl(array, new Object[] { array }, null);
| private static java.lang.String | deepToStringImpl(java.lang.Object[] array, java.lang.Object[] origArrays, java.lang.StringBuilder sb)
Implementation method used by {@link #deepToString(Object[])}.
if (array == null) {
return "null"; //$NON-NLS-1$
}
if (array.length == 0) {
return "[]"; //$NON-NLS-1$
}
if (sb == null) {
sb = new StringBuilder(2 + array.length * 5);
}
sb.append('[");
for (int i = 0; i < array.length; i++) {
if (i != 0) {
sb.append(", "); //$NON-NLS-1$
}
// establish current element
Object elem = array[i];
if (elem == null) {
// element is null
sb.append("null"); //$NON-NLS-1$
} else {
// get the Class of the current element
Class<?> elemClass = elem.getClass();
if (elemClass.isArray()) {
// element is an array type
// get the declared Class of the array (element)
Class<?> elemElemClass = elemClass.getComponentType();
if (elemElemClass.isPrimitive()) {
// element is a primitive array
if (boolean.class.equals(elemElemClass)) {
sb.append(toString((boolean[]) elem));
} else if (byte.class.equals(elemElemClass)) {
sb.append(toString((byte[]) elem));
} else if (char.class.equals(elemElemClass)) {
sb.append(toString((char[]) elem));
} else if (double.class.equals(elemElemClass)) {
sb.append(toString((double[]) elem));
} else if (float.class.equals(elemElemClass)) {
sb.append(toString((float[]) elem));
} else if (int.class.equals(elemElemClass)) {
sb.append(toString((int[]) elem));
} else if (long.class.equals(elemElemClass)) {
sb.append(toString((long[]) elem));
} else if (short.class.equals(elemElemClass)) {
sb.append(toString((short[]) elem));
} else {
// no other possible primitives, so we assert that
throw new AssertionError();
}
} else {
// element is an Object[], so we assert that
assert elem instanceof Object[];
if (deepToStringImplContains(origArrays, elem)) {
sb.append("[...]"); //$NON-NLS-1$
} else {
Object[] newArray = (Object[]) elem;
Object[] newOrigArrays = new Object[origArrays.length + 1];
System.arraycopy(origArrays, 0, newOrigArrays, 0,
origArrays.length);
newOrigArrays[origArrays.length] = newArray;
// make the recursive call to this method
deepToStringImpl(newArray, newOrigArrays, sb);
}
}
} else { // element is NOT an array, just an Object
sb.append(array[i]);
}
}
}
sb.append(']");
return sb.toString();
| private static boolean | deepToStringImplContains(java.lang.Object[] origArrays, java.lang.Object array)
Utility method used to assist the implementation of
{@link #deepToString(Object[])}.
if (origArrays == null || origArrays.length == 0) {
return false;
}
for (Object element : origArrays) {
if (element == array) {
return true;
}
}
return false;
| public static boolean | equals(byte[] array1, byte[] array2)Compares the two arrays.
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
if (array1[i] != array2[i]) {
return false;
}
}
return true;
| public static boolean | equals(short[] array1, short[] array2)Compares the two arrays.
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
if (array1[i] != array2[i]) {
return false;
}
}
return true;
| public static boolean | equals(char[] array1, char[] array2)Compares the two arrays.
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
if (array1[i] != array2[i]) {
return false;
}
}
return true;
| public static boolean | equals(int[] array1, int[] array2)Compares the two arrays.
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
if (array1[i] != array2[i]) {
return false;
}
}
return true;
| public static boolean | equals(long[] array1, long[] array2)Compares the two arrays.
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
if (array1[i] != array2[i]) {
return false;
}
}
return true;
| public static boolean | equals(float[] array1, float[] array2)Compares the two arrays. The values are compared in the same manner as
{@code Float.equals()}.
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
if (Float.floatToIntBits(array1[i]) != Float
.floatToIntBits(array2[i])) {
return false;
}
}
return true;
| public static boolean | equals(double[] array1, double[] array2)Compares the two arrays. The values are compared in the same manner as
{@code Double.equals()}.
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
if (Double.doubleToLongBits(array1[i]) != Double
.doubleToLongBits(array2[i])) {
return false;
}
}
return true;
| public static boolean | equals(boolean[] array1, boolean[] array2)Compares the two arrays.
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
if (array1[i] != array2[i]) {
return false;
}
}
return true;
| public static boolean | equals(java.lang.Object[] array1, java.lang.Object[] array2)Compares the two arrays.
if (array1 == array2) {
return true;
}
if (array1 == null || array2 == null || array1.length != array2.length) {
return false;
}
for (int i = 0; i < array1.length; i++) {
Object e1 = array1[i], e2 = array2[i];
if (!(e1 == null ? e2 == null : e1.equals(e2))) {
return false;
}
}
return true;
| public static void | fill(byte[] array, byte value)Fills the specified array with the specified element.
for (int i = 0; i < array.length; i++) {
array[i] = value;
}
| public static void | fill(byte[] array, int start, int end, byte value)Fills the specified range in the array with the specified element.
// Check for null first
int length = array.length;
if (start > end) {
throw new IllegalArgumentException();
}
if (start < 0 || end > length) {
throw new ArrayIndexOutOfBoundsException();
}
for (int i = start; i < end; i++) {
array[i] = value;
}
| public static void | fill(short[] array, short value)Fills the specified array with the specified element.
for (int i = 0; i < array.length; i++) {
array[i] = value;
}
| public static void | fill(short[] array, int start, int end, short value)Fills the specified range in the array with the specified element.
// Check for null first
int length = array.length;
if (start > end) {
throw new IllegalArgumentException();
}
if (start < 0 || end > length) {
throw new ArrayIndexOutOfBoundsException();
}
for (int i = start; i < end; i++) {
array[i] = value;
}
| public static void | fill(char[] array, char value)Fills the specified array with the specified element.
for (int i = 0; i < array.length; i++) {
array[i] = value;
}
| public static void | fill(char[] array, int start, int end, char value)Fills the specified range in the array with the specified element.
// Check for null first
int length = array.length;
if (start > end) {
throw new IllegalArgumentException();
}
if (start < 0 || end > length) {
throw new ArrayIndexOutOfBoundsException();
}
for (int i = start; i < end; i++) {
array[i] = value;
}
| public static void | fill(int[] array, int value)Fills the specified array with the specified element.
for (int i = 0; i < array.length; i++) {
array[i] = value;
}
| public static void | fill(int[] array, int start, int end, int value)Fills the specified range in the array with the specified element.
// Check for null first
int length = array.length;
if (start > end) {
throw new IllegalArgumentException();
}
if (start < 0 || end > length) {
throw new ArrayIndexOutOfBoundsException();
}
for (int i = start; i < end; i++) {
array[i] = value;
}
| public static void | fill(long[] array, long value)Fills the specified array with the specified element.
for (int i = 0; i < array.length; i++) {
array[i] = value;
}
| public static void | fill(long[] array, int start, int end, long value)Fills the specified range in the array with the specified element.
// Check for null first
int length = array.length;
if (start > end) {
throw new IllegalArgumentException();
}
if (start < 0 || end > length) {
throw new ArrayIndexOutOfBoundsException();
}
for (int i = start; i < end; i++) {
array[i] = value;
}
| public static void | fill(float[] array, float value)Fills the specified array with the specified element.
for (int i = 0; i < array.length; i++) {
array[i] = value;
}
| public static void | fill(float[] array, int start, int end, float value)Fills the specified range in the array with the specified element.
// Check for null first
int length = array.length;
if (start > end) {
throw new IllegalArgumentException();
}
if (start < 0 || end > length) {
throw new ArrayIndexOutOfBoundsException();
}
for (int i = start; i < end; i++) {
array[i] = value;
}
| public static void | fill(double[] array, double value)Fills the specified array with the specified element.
for (int i = 0; i < array.length; i++) {
array[i] = value;
}
| public static void | fill(double[] array, int start, int end, double value)Fills the specified range in the array with the specified element.
// Check for null first
int length = array.length;
if (start > end) {
throw new IllegalArgumentException();
}
if (start < 0 || end > length) {
throw new ArrayIndexOutOfBoundsException();
}
for (int i = start; i < end; i++) {
array[i] = value;
}
| public static void | fill(boolean[] array, boolean value)Fills the specified array with the specified element.
for (int i = 0; i < array.length; i++) {
array[i] = value;
}
| public static void | fill(boolean[] array, int start, int end, boolean value)Fills the specified range in the array with the specified element.
// Check for null first
int length = array.length;
if (start > end) {
throw new IllegalArgumentException();
}
if (start < 0 || end > length) {
throw new ArrayIndexOutOfBoundsException();
}
for (int i = start; i < end; i++) {
array[i] = value;
}
| public static void | fill(java.lang.Object[] array, java.lang.Object value)Fills the specified array with the specified element.
for (int i = 0; i < array.length; i++) {
array[i] = value;
}
| public static void | fill(java.lang.Object[] array, int start, int end, java.lang.Object value)Fills the specified range in the array with the specified element.
// Check for null first
int length = array.length;
if (start > end) {
throw new IllegalArgumentException();
}
if (start < 0 || end > length) {
throw new ArrayIndexOutOfBoundsException();
}
for (int i = start; i < end; i++) {
array[i] = value;
}
| public static int | hashCode(boolean[] array)Returns a hash code based on the contents of the given array. For any two
{@code boolean} arrays {@code a} and {@code b}, if
{@code Arrays.equals(a, b)} returns {@code true}, it means
that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
The value returned by this method is the same value as the
{@link List#hashCode()}} method which is invoked on a {@link List}}
containing a sequence of {@link Boolean}} instances representing the
elements of array in the same order. If the array is {@code null}, the return
value is 0.
if (array == null) {
return 0;
}
int hashCode = 1;
for (boolean element : array) {
// 1231, 1237 are hash code values for boolean value
hashCode = 31 * hashCode + (element ? 1231 : 1237);
}
return hashCode;
| public static int | hashCode(int[] array)Returns a hash code based on the contents of the given array. For any two
not-null {@code int} arrays {@code a} and {@code b}, if
{@code Arrays.equals(a, b)} returns {@code true}, it means
that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
The value returned by this method is the same value as the
{@link List#hashCode()}} method which is invoked on a {@link List}}
containing a sequence of {@link Integer}} instances representing the
elements of array in the same order. If the array is {@code null}, the return
value is 0.
if (array == null) {
return 0;
}
int hashCode = 1;
for (int element : array) {
// the hash code value for integer value is integer value itself
hashCode = 31 * hashCode + element;
}
return hashCode;
| public static int | hashCode(short[] array)Returns a hash code based on the contents of the given array. For any two
{@code short} arrays {@code a} and {@code b}, if
{@code Arrays.equals(a, b)} returns {@code true}, it means
that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
The value returned by this method is the same value as the
{@link List#hashCode()}} method which is invoked on a {@link List}}
containing a sequence of {@link Short}} instances representing the
elements of array in the same order. If the array is {@code null}, the return
value is 0.
if (array == null) {
return 0;
}
int hashCode = 1;
for (short element : array) {
// the hash code value for short value is its integer value
hashCode = 31 * hashCode + element;
}
return hashCode;
| public static int | hashCode(char[] array)Returns a hash code based on the contents of the given array. For any two
{@code char} arrays {@code a} and {@code b}, if
{@code Arrays.equals(a, b)} returns {@code true}, it means
that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
The value returned by this method is the same value as the
{@link List#hashCode()}} method which is invoked on a {@link List}}
containing a sequence of {@link Character}} instances representing the
elements of array in the same order. If the array is {@code null}, the return
value is 0.
if (array == null) {
return 0;
}
int hashCode = 1;
for (char element : array) {
// the hash code value for char value is its integer value
hashCode = 31 * hashCode + element;
}
return hashCode;
| public static int | hashCode(byte[] array)Returns a hash code based on the contents of the given array. For any two
{@code byte} arrays {@code a} and {@code b}, if
{@code Arrays.equals(a, b)} returns {@code true}, it means
that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
The value returned by this method is the same value as the
{@link List#hashCode()}} method which is invoked on a {@link List}}
containing a sequence of {@link Byte}} instances representing the
elements of array in the same order. If the array is {@code null}, the return
value is 0.
if (array == null) {
return 0;
}
int hashCode = 1;
for (byte element : array) {
// the hash code value for byte value is its integer value
hashCode = 31 * hashCode + element;
}
return hashCode;
| public static int | hashCode(long[] array)Returns a hash code based on the contents of the given array. For any two
{@code long} arrays {@code a} and {@code b}, if
{@code Arrays.equals(a, b)} returns {@code true}, it means
that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
The value returned by this method is the same value as the
{@link List#hashCode()}} method which is invoked on a {@link List}}
containing a sequence of {@link Long}} instances representing the
elements of array in the same order. If the array is {@code null}, the return
value is 0.
if (array == null) {
return 0;
}
int hashCode = 1;
for (long elementValue : array) {
/*
* the hash code value for long value is (int) (value ^ (value >>>
* 32))
*/
hashCode = 31 * hashCode
+ (int) (elementValue ^ (elementValue >>> 32));
}
return hashCode;
| public static int | hashCode(float[] array)Returns a hash code based on the contents of the given array. For any two
{@code float} arrays {@code a} and {@code b}, if
{@code Arrays.equals(a, b)} returns {@code true}, it means
that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
The value returned by this method is the same value as the
{@link List#hashCode()}} method which is invoked on a {@link List}}
containing a sequence of {@link Float}} instances representing the
elements of array in the same order. If the array is {@code null}, the return
value is 0.
if (array == null) {
return 0;
}
int hashCode = 1;
for (float element : array) {
/*
* the hash code value for float value is
* Float.floatToIntBits(value)
*/
hashCode = 31 * hashCode + Float.floatToIntBits(element);
}
return hashCode;
| public static int | hashCode(double[] array)Returns a hash code based on the contents of the given array. For any two
{@code double} arrays {@code a} and {@code b}, if
{@code Arrays.equals(a, b)} returns {@code true}, it means
that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
The value returned by this method is the same value as the
{@link List#hashCode()}} method which is invoked on a {@link List}}
containing a sequence of {@link Double}} instances representing the
elements of array in the same order. If the array is {@code null}, the return
value is 0.
if (array == null) {
return 0;
}
int hashCode = 1;
for (double element : array) {
long v = Double.doubleToLongBits(element);
/*
* the hash code value for double value is (int) (v ^ (v >>> 32))
* where v = Double.doubleToLongBits(value)
*/
hashCode = 31 * hashCode + (int) (v ^ (v >>> 32));
}
return hashCode;
| public static int | hashCode(java.lang.Object[] array)Returns a hash code based on the contents of the given array. If the
array contains other arrays as its elements, the hash code is based on
their identities not their contents. So it is acceptable to invoke this
method on an array that contains itself as an element, either directly or
indirectly.
For any two arrays {@code a} and {@code b}, if
{@code Arrays.equals(a, b)} returns {@code true}, it means
that the return value of {@code Arrays.hashCode(a)} equals
{@code Arrays.hashCode(b)}.
The value returned by this method is the same value as the method
Arrays.asList(array).hashCode(). If the array is {@code null}, the return value
is 0.
if (array == null) {
return 0;
}
int hashCode = 1;
for (Object element : array) {
int elementHashCode;
if (element == null) {
elementHashCode = 0;
} else {
elementHashCode = (element).hashCode();
}
hashCode = 31 * hashCode + elementHashCode;
}
return hashCode;
| private static boolean | lessThan(double double1, double double2)
long d1, d2;
long NaNbits = Double.doubleToLongBits(Double.NaN);
if ((d1 = Double.doubleToLongBits(double1)) == NaNbits) {
return false;
}
if ((d2 = Double.doubleToLongBits(double2)) == NaNbits) {
return true;
}
if (double1 == double2) {
if (d1 == d2) {
return false;
}
// check for -0
return d1 < d2;
}
return double1 < double2;
| private static boolean | lessThan(float float1, float float2)
int f1, f2;
int NaNbits = Float.floatToIntBits(Float.NaN);
if ((f1 = Float.floatToIntBits(float1)) == NaNbits) {
return false;
}
if ((f2 = Float.floatToIntBits(float2)) == NaNbits) {
return true;
}
if (float1 == float2) {
if (f1 == f2) {
return false;
}
// check for -0
return f1 < f2;
}
return float1 < float2;
| private static int | med3(byte[] array, int a, int b, int c)
byte x = array[a], y = array[b], z = array[c];
return x < y ? (y < z ? b : (x < z ? c : a)) : (y > z ? b : (x > z ? c
: a));
| private static int | med3(char[] array, int a, int b, int c)
char x = array[a], y = array[b], z = array[c];
return x < y ? (y < z ? b : (x < z ? c : a)) : (y > z ? b : (x > z ? c
: a));
| private static int | med3(double[] array, int a, int b, int c)
double x = array[a], y = array[b], z = array[c];
return lessThan(x, y) ? (lessThan(y, z) ? b : (lessThan(x, z) ? c : a))
: (lessThan(z, y) ? b : (lessThan(z, x) ? c : a));
| private static int | med3(float[] array, int a, int b, int c)
float x = array[a], y = array[b], z = array[c];
return lessThan(x, y) ? (lessThan(y, z) ? b : (lessThan(x, z) ? c : a))
: (lessThan(z, y) ? b : (lessThan(z, x) ? c : a));
| private static int | med3(int[] array, int a, int b, int c)
int x = array[a], y = array[b], z = array[c];
return x < y ? (y < z ? b : (x < z ? c : a)) : (y > z ? b : (x > z ? c
: a));
| private static int | med3(long[] array, int a, int b, int c)
long x = array[a], y = array[b], z = array[c];
return x < y ? (y < z ? b : (x < z ? c : a)) : (y > z ? b : (x > z ? c
: a));
| private static int | med3(short[] array, int a, int b, int c)
short x = array[a], y = array[b], z = array[c];
return x < y ? (y < z ? b : (x < z ? c : a)) : (y > z ? b : (x > z ? c
: a));
| public static void | sort(byte[] array)Sorts the specified array in ascending numerical order.
sort(0, array.length, array);
| public static void | sort(byte[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.
if (array == null) {
throw new NullPointerException();
}
checkBounds(array.length, start, end);
sort(start, end, array);
| private static void | sort(int start, int end, byte[] array)
byte temp;
int length = end - start;
if (length < 7) {
for (int i = start + 1; i < end; i++) {
for (int j = i; j > start && array[j - 1] > array[j]; j--) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
return;
}
int middle = (start + end) / 2;
if (length > 7) {
int bottom = start;
int top = end - 1;
if (length > 40) {
length /= 8;
bottom = med3(array, bottom, bottom + length, bottom
+ (2 * length));
middle = med3(array, middle - length, middle, middle + length);
top = med3(array, top - (2 * length), top - length, top);
}
middle = med3(array, bottom, middle, top);
}
byte partionValue = array[middle];
int a, b, c, d;
a = b = start;
c = d = end - 1;
while (true) {
while (b <= c && array[b] <= partionValue) {
if (array[b] == partionValue) {
temp = array[a];
array[a++] = array[b];
array[b] = temp;
}
b++;
}
while (c >= b && array[c] >= partionValue) {
if (array[c] == partionValue) {
temp = array[c];
array[c] = array[d];
array[d--] = temp;
}
c--;
}
if (b > c) {
break;
}
temp = array[b];
array[b++] = array[c];
array[c--] = temp;
}
length = a - start < b - a ? a - start : b - a;
int l = start;
int h = b - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
length = d - c < end - 1 - d ? d - c : end - 1 - d;
l = b;
h = end - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
if ((length = b - a) > 0) {
sort(start, start + length, array);
}
if ((length = d - c) > 0) {
sort(end - length, end, array);
}
| public static void | sort(char[] array)Sorts the specified array in ascending numerical order.
sort(0, array.length, array);
| public static void | sort(char[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.
if (array == null) {
throw new NullPointerException();
}
checkBounds(array.length, start, end);
sort(start, end, array);
| private static void | sort(int start, int end, char[] array)
char temp;
int length = end - start;
if (length < 7) {
for (int i = start + 1; i < end; i++) {
for (int j = i; j > start && array[j - 1] > array[j]; j--) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
return;
}
int middle = (start + end) / 2;
if (length > 7) {
int bottom = start;
int top = end - 1;
if (length > 40) {
length /= 8;
bottom = med3(array, bottom, bottom + length, bottom
+ (2 * length));
middle = med3(array, middle - length, middle, middle + length);
top = med3(array, top - (2 * length), top - length, top);
}
middle = med3(array, bottom, middle, top);
}
char partionValue = array[middle];
int a, b, c, d;
a = b = start;
c = d = end - 1;
while (true) {
while (b <= c && array[b] <= partionValue) {
if (array[b] == partionValue) {
temp = array[a];
array[a++] = array[b];
array[b] = temp;
}
b++;
}
while (c >= b && array[c] >= partionValue) {
if (array[c] == partionValue) {
temp = array[c];
array[c] = array[d];
array[d--] = temp;
}
c--;
}
if (b > c) {
break;
}
temp = array[b];
array[b++] = array[c];
array[c--] = temp;
}
length = a - start < b - a ? a - start : b - a;
int l = start;
int h = b - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
length = d - c < end - 1 - d ? d - c : end - 1 - d;
l = b;
h = end - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
if ((length = b - a) > 0) {
sort(start, start + length, array);
}
if ((length = d - c) > 0) {
sort(end - length, end, array);
}
| public static void | sort(double[] array)Sorts the specified array in ascending numerical order.
sort(0, array.length, array);
| public static void | sort(double[] array, int start, int end)Sorts the specified range in the array in ascending numerical order. The
values are sorted according to the order imposed by {@code Double.compareTo()}.
if (array == null) {
throw new NullPointerException();
}
checkBounds(array.length, start, end);
sort(start, end, array);
| private static void | sort(int start, int end, double[] array)
double temp;
int length = end - start;
if (length < 7) {
for (int i = start + 1; i < end; i++) {
for (int j = i; j > start && lessThan(array[j], array[j - 1]); j--) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
return;
}
int middle = (start + end) / 2;
if (length > 7) {
int bottom = start;
int top = end - 1;
if (length > 40) {
length /= 8;
bottom = med3(array, bottom, bottom + length, bottom
+ (2 * length));
middle = med3(array, middle - length, middle, middle + length);
top = med3(array, top - (2 * length), top - length, top);
}
middle = med3(array, bottom, middle, top);
}
double partionValue = array[middle];
int a, b, c, d;
a = b = start;
c = d = end - 1;
while (true) {
while (b <= c && !lessThan(partionValue, array[b])) {
if (array[b] == partionValue) {
temp = array[a];
array[a++] = array[b];
array[b] = temp;
}
b++;
}
while (c >= b && !lessThan(array[c], partionValue)) {
if (array[c] == partionValue) {
temp = array[c];
array[c] = array[d];
array[d--] = temp;
}
c--;
}
if (b > c) {
break;
}
temp = array[b];
array[b++] = array[c];
array[c--] = temp;
}
length = a - start < b - a ? a - start : b - a;
int l = start;
int h = b - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
length = d - c < end - 1 - d ? d - c : end - 1 - d;
l = b;
h = end - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
if ((length = b - a) > 0) {
sort(start, start + length, array);
}
if ((length = d - c) > 0) {
sort(end - length, end, array);
}
| public static void | sort(float[] array)Sorts the specified array in ascending numerical order.
sort(0, array.length, array);
| public static void | sort(float[] array, int start, int end)Sorts the specified range in the array in ascending numerical order. The
values are sorted according to the order imposed by {@code Float.compareTo()}.
if (array == null) {
throw new NullPointerException();
}
checkBounds(array.length, start, end);
sort(start, end, array);
| private static void | sort(int start, int end, float[] array)
float temp;
int length = end - start;
if (length < 7) {
for (int i = start + 1; i < end; i++) {
for (int j = i; j > start && lessThan(array[j], array[j - 1]); j--) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
return;
}
int middle = (start + end) / 2;
if (length > 7) {
int bottom = start;
int top = end - 1;
if (length > 40) {
length /= 8;
bottom = med3(array, bottom, bottom + length, bottom
+ (2 * length));
middle = med3(array, middle - length, middle, middle + length);
top = med3(array, top - (2 * length), top - length, top);
}
middle = med3(array, bottom, middle, top);
}
float partionValue = array[middle];
int a, b, c, d;
a = b = start;
c = d = end - 1;
while (true) {
while (b <= c && !lessThan(partionValue, array[b])) {
if (array[b] == partionValue) {
temp = array[a];
array[a++] = array[b];
array[b] = temp;
}
b++;
}
while (c >= b && !lessThan(array[c], partionValue)) {
if (array[c] == partionValue) {
temp = array[c];
array[c] = array[d];
array[d--] = temp;
}
c--;
}
if (b > c) {
break;
}
temp = array[b];
array[b++] = array[c];
array[c--] = temp;
}
length = a - start < b - a ? a - start : b - a;
int l = start;
int h = b - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
length = d - c < end - 1 - d ? d - c : end - 1 - d;
l = b;
h = end - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
if ((length = b - a) > 0) {
sort(start, start + length, array);
}
if ((length = d - c) > 0) {
sort(end - length, end, array);
}
| public static void | sort(int[] array)Sorts the specified array in ascending numerical order.
sort(0, array.length, array);
| public static void | sort(int[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.
if (array == null) {
throw new NullPointerException();
}
checkBounds(array.length, start, end);
sort(start, end, array);
| private static void | sort(int start, int end, int[] array)
int temp;
int length = end - start;
if (length < 7) {
for (int i = start + 1; i < end; i++) {
for (int j = i; j > start && array[j - 1] > array[j]; j--) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
return;
}
int middle = (start + end) / 2;
if (length > 7) {
int bottom = start;
int top = end - 1;
if (length > 40) {
length /= 8;
bottom = med3(array, bottom, bottom + length, bottom
+ (2 * length));
middle = med3(array, middle - length, middle, middle + length);
top = med3(array, top - (2 * length), top - length, top);
}
middle = med3(array, bottom, middle, top);
}
int partionValue = array[middle];
int a, b, c, d;
a = b = start;
c = d = end - 1;
while (true) {
while (b <= c && array[b] <= partionValue) {
if (array[b] == partionValue) {
temp = array[a];
array[a++] = array[b];
array[b] = temp;
}
b++;
}
while (c >= b && array[c] >= partionValue) {
if (array[c] == partionValue) {
temp = array[c];
array[c] = array[d];
array[d--] = temp;
}
c--;
}
if (b > c) {
break;
}
temp = array[b];
array[b++] = array[c];
array[c--] = temp;
}
length = a - start < b - a ? a - start : b - a;
int l = start;
int h = b - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
length = d - c < end - 1 - d ? d - c : end - 1 - d;
l = b;
h = end - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
if ((length = b - a) > 0) {
sort(start, start + length, array);
}
if ((length = d - c) > 0) {
sort(end - length, end, array);
}
| public static void | sort(long[] array)Sorts the specified array in ascending numerical order.
sort(0, array.length, array);
| public static void | sort(long[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.
if (array == null) {
throw new NullPointerException();
}
checkBounds(array.length, start, end);
sort(start, end, array);
| private static void | sort(int start, int end, long[] array)
long temp;
int length = end - start;
if (length < 7) {
for (int i = start + 1; i < end; i++) {
for (int j = i; j > start && array[j - 1] > array[j]; j--) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
return;
}
int middle = (start + end) / 2;
if (length > 7) {
int bottom = start;
int top = end - 1;
if (length > 40) {
length /= 8;
bottom = med3(array, bottom, bottom + length, bottom
+ (2 * length));
middle = med3(array, middle - length, middle, middle + length);
top = med3(array, top - (2 * length), top - length, top);
}
middle = med3(array, bottom, middle, top);
}
long partionValue = array[middle];
int a, b, c, d;
a = b = start;
c = d = end - 1;
while (true) {
while (b <= c && array[b] <= partionValue) {
if (array[b] == partionValue) {
temp = array[a];
array[a++] = array[b];
array[b] = temp;
}
b++;
}
while (c >= b && array[c] >= partionValue) {
if (array[c] == partionValue) {
temp = array[c];
array[c] = array[d];
array[d--] = temp;
}
c--;
}
if (b > c) {
break;
}
temp = array[b];
array[b++] = array[c];
array[c--] = temp;
}
length = a - start < b - a ? a - start : b - a;
int l = start;
int h = b - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
length = d - c < end - 1 - d ? d - c : end - 1 - d;
l = b;
h = end - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
if ((length = b - a) > 0) {
sort(start, start + length, array);
}
if ((length = d - c) > 0) {
sort(end - length, end, array);
}
| public static void | sort(java.lang.Object[] array)Sorts the specified array in ascending natural order.
ComparableTimSort.sort(array);
| public static void | sort(java.lang.Object[] array, int start, int end)Sorts the specified range in the array in ascending natural order. All
elements must implement the {@code Comparable} interface and must be
comparable to each other without a {@code ClassCastException} being
thrown.
ComparableTimSort.sort(array, start, end);
| public static void | sort(T[] array, int start, int end, java.util.Comparator comparator)Sorts the specified range in the array using the specified {@code Comparator}.
All elements must be comparable to each other without a
{@code ClassCastException} being thrown.
TimSort.sort(array, start, end, comparator);
| public static void | sort(T[] array, java.util.Comparator comparator)Sorts the specified array using the specified {@code Comparator}. All elements
must be comparable to each other without a {@code ClassCastException} being thrown.
TimSort.sort(array, comparator);
| public static void | sort(short[] array)Sorts the specified array in ascending numerical order.
sort(0, array.length, array);
| public static void | sort(short[] array, int start, int end)Sorts the specified range in the array in ascending numerical order.
if (array == null) {
throw new NullPointerException();
}
checkBounds(array.length, start, end);
sort(start, end, array);
| private static void | sort(int start, int end, short[] array)
short temp;
int length = end - start;
if (length < 7) {
for (int i = start + 1; i < end; i++) {
for (int j = i; j > start && array[j - 1] > array[j]; j--) {
temp = array[j];
array[j] = array[j - 1];
array[j - 1] = temp;
}
}
return;
}
int middle = (start + end) / 2;
if (length > 7) {
int bottom = start;
int top = end - 1;
if (length > 40) {
length /= 8;
bottom = med3(array, bottom, bottom + length, bottom
+ (2 * length));
middle = med3(array, middle - length, middle, middle + length);
top = med3(array, top - (2 * length), top - length, top);
}
middle = med3(array, bottom, middle, top);
}
short partionValue = array[middle];
int a, b, c, d;
a = b = start;
c = d = end - 1;
while (true) {
while (b <= c && array[b] <= partionValue) {
if (array[b] == partionValue) {
temp = array[a];
array[a++] = array[b];
array[b] = temp;
}
b++;
}
while (c >= b && array[c] >= partionValue) {
if (array[c] == partionValue) {
temp = array[c];
array[c] = array[d];
array[d--] = temp;
}
c--;
}
if (b > c) {
break;
}
temp = array[b];
array[b++] = array[c];
array[c--] = temp;
}
length = a - start < b - a ? a - start : b - a;
int l = start;
int h = b - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
length = d - c < end - 1 - d ? d - c : end - 1 - d;
l = b;
h = end - length;
while (length-- > 0) {
temp = array[l];
array[l++] = array[h];
array[h++] = temp;
}
if ((length = b - a) > 0) {
sort(start, start + length, array);
}
if ((length = d - c) > 0) {
sort(end - length, end, array);
}
| public static java.lang.String | toString(boolean[] array)
Creates a {@code String} representation of the {@code boolean[]} passed.
The result is surrounded by brackets ({@code "[]"}), each
element is converted to a {@code String} via the
{@link String#valueOf(boolean)} and separated by {@code ", "}.
If the array is {@code null}, then {@code "null"} is returned.
if (array == null) {
return "null"; //$NON-NLS-1$
}
if (array.length == 0) {
return "[]"; //$NON-NLS-1$
}
StringBuilder sb = new StringBuilder(2 + array.length * 5);
sb.append('[");
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
sb.append(", "); //$NON-NLS-1$
sb.append(array[i]);
}
sb.append(']");
return sb.toString();
| public static java.lang.String | toString(byte[] array)
Creates a {@code String} representation of the {@code byte[]} passed. The
result is surrounded by brackets ({@code "[]"}), each element
is converted to a {@code String} via the {@link String#valueOf(int)} and
separated by {@code ", "}. If the array is {@code null}, then
{@code "null"} is returned.
if (array == null) {
return "null"; //$NON-NLS-1$
}
if (array.length == 0) {
return "[]"; //$NON-NLS-1$
}
StringBuilder sb = new StringBuilder(2 + array.length * 3);
sb.append('[");
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
sb.append(", "); //$NON-NLS-1$
sb.append(array[i]);
}
sb.append(']");
return sb.toString();
| public static java.lang.String | toString(char[] array)
Creates a {@code String} representation of the {@code char[]} passed. The
result is surrounded by brackets ({@code "[]"}), each element
is converted to a {@code String} via the {@link String#valueOf(char)} and
separated by {@code ", "}. If the array is {@code null}, then
{@code "null"} is returned.
if (array == null) {
return "null"; //$NON-NLS-1$
}
if (array.length == 0) {
return "[]"; //$NON-NLS-1$
}
StringBuilder sb = new StringBuilder(2 + array.length * 2);
sb.append('[");
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
sb.append(", "); //$NON-NLS-1$
sb.append(array[i]);
}
sb.append(']");
return sb.toString();
| public static java.lang.String | toString(double[] array)
Creates a {@code String} representation of the {@code double[]} passed.
The result is surrounded by brackets ({@code "[]"}), each
element is converted to a {@code String} via the
{@link String#valueOf(double)} and separated by {@code ", "}.
If the array is {@code null}, then {@code "null"} is returned.
if (array == null) {
return "null"; //$NON-NLS-1$
}
if (array.length == 0) {
return "[]"; //$NON-NLS-1$
}
StringBuilder sb = new StringBuilder(2 + array.length * 5);
sb.append('[");
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
sb.append(", "); //$NON-NLS-1$
sb.append(array[i]);
}
sb.append(']");
return sb.toString();
| public static java.lang.String | toString(float[] array)
Creates a {@code String} representation of the {@code float[]} passed.
The result is surrounded by brackets ({@code "[]"}), each
element is converted to a {@code String} via the
{@link String#valueOf(float)} and separated by {@code ", "}.
If the array is {@code null}, then {@code "null"} is returned.
if (array == null) {
return "null"; //$NON-NLS-1$
}
if (array.length == 0) {
return "[]"; //$NON-NLS-1$
}
StringBuilder sb = new StringBuilder(2 + array.length * 5);
sb.append('[");
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
sb.append(", "); //$NON-NLS-1$
sb.append(array[i]);
}
sb.append(']");
return sb.toString();
| public static java.lang.String | toString(int[] array)
Creates a {@code String} representation of the {@code int[]} passed. The
result is surrounded by brackets ({@code "[]"}), each element
is converted to a {@code String} via the {@link String#valueOf(int)} and
separated by {@code ", "}. If the array is {@code null}, then
{@code "null"} is returned.
if (array == null) {
return "null"; //$NON-NLS-1$
}
if (array.length == 0) {
return "[]"; //$NON-NLS-1$
}
StringBuilder sb = new StringBuilder(2 + array.length * 4);
sb.append('[");
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
sb.append(", "); //$NON-NLS-1$
sb.append(array[i]);
}
sb.append(']");
return sb.toString();
| public static java.lang.String | toString(long[] array)
Creates a {@code String} representation of the {@code long[]} passed. The
result is surrounded by brackets ({@code "[]"}), each element
is converted to a {@code String} via the {@link String#valueOf(long)} and
separated by {@code ", "}. If the array is {@code null}, then
{@code "null"} is returned.
if (array == null) {
return "null"; //$NON-NLS-1$
}
if (array.length == 0) {
return "[]"; //$NON-NLS-1$
}
StringBuilder sb = new StringBuilder(2 + array.length * 4);
sb.append('[");
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
sb.append(", "); //$NON-NLS-1$
sb.append(array[i]);
}
sb.append(']");
return sb.toString();
| public static java.lang.String | toString(short[] array)
Creates a {@code String} representation of the {@code short[]} passed.
The result is surrounded by brackets ({@code "[]"}), each
element is converted to a {@code String} via the
{@link String#valueOf(int)} and separated by {@code ", "}. If
the array is {@code null}, then {@code "null"} is returned.
if (array == null) {
return "null"; //$NON-NLS-1$
}
if (array.length == 0) {
return "[]"; //$NON-NLS-1$
}
StringBuilder sb = new StringBuilder(2 + array.length * 4);
sb.append('[");
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
sb.append(", "); //$NON-NLS-1$
sb.append(array[i]);
}
sb.append(']");
return sb.toString();
| public static java.lang.String | toString(java.lang.Object[] array)
Creates a {@code String} representation of the {@code Object[]} passed.
The result is surrounded by brackets ({@code "[]"}), each
element is converted to a {@code String} via the
{@link String#valueOf(Object)} and separated by {@code ", "}.
If the array is {@code null}, then {@code "null"} is returned.
if (array == null) {
return "null"; //$NON-NLS-1$
}
if (array.length == 0) {
return "[]"; //$NON-NLS-1$
}
StringBuilder sb = new StringBuilder(2 + array.length * 5);
sb.append('[");
sb.append(array[0]);
for (int i = 1; i < array.length; i++) {
sb.append(", "); //$NON-NLS-1$
sb.append(array[i]);
}
sb.append(']");
return sb.toString();
|
|