public class ArrayUtil extends Object
Constructor and Description |
---|
ArrayUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
arraycopy(byte[] src,
int src_position,
byte[] dst,
int dst_position,
int length)
This is really a debugging version of
System.arraycopy() . |
static void |
arrayMoveWithin(Object[] array,
int moveFrom,
int moveTo,
int numToMove)
Moves a number of entries in an array to another point in the array,
shifting those inbetween as required.
|
static byte[] |
copyOf(byte[] source,
int newLength)
Copies the specified array, truncating or padding with zeros (if
necessary) so the copy has the specified length.
|
static <T> T[] |
copyOf(T[] source,
T[] result)
Copies the specified array into specified result array, truncating or
padding with zeros (if necessary) so the copy has the specified length.
|
static byte[] |
copyOfRange(byte[] original,
int from,
int to)
Copies the specified range of the specified array into a new array.
|
public static void arraycopy(byte[] src, int src_position, byte[] dst, int dst_position, int length)
System.arraycopy()
.
Use it to provide better exception messages when copying arrays around.
For production use it's better to use the original for speed.public static void arrayMoveWithin(Object[] array, int moveFrom, int moveTo, int numToMove)
array
- The array to altermoveFrom
- The (0 based) index of the first entry to movemoveTo
- The (0 based) index of the positition to move tonumToMove
- The number of entries to movepublic static byte[] copyOf(byte[] source, int newLength)
source
- the array to be copiednewLength
- the length of the copy to be returnedNegativeArraySizeException
- if newLength is negativeNullPointerException
- if original is nullpublic static <T> T[] copyOf(T[] source, T[] result)
source
- the array to be copiedresult
- the array to be filled and returnedNegativeArraySizeException
- if newLength is negativeNullPointerException
- if original is nullpublic static byte[] copyOfRange(byte[] original, int from, int to)
original
- the array from which a range is to be copiedfrom
- the initial index of the range to be copied, inclusiveto
- the final index of the range to be copied, exclusive.
(This index may lie outside the array.)ArrayIndexOutOfBoundsException
- if from < 0
or from > original.length()IllegalArgumentException
- if from > toNullPointerException
- if original is nullCopyright © 2020. All rights reserved.