Class ArrayUtil
is a collection of static methods to manipulate arrays. The idea
is that the currently used area in the array is stored somewhere
else. The functions in here, except resize(),
pretend the whole array is in use.
This will hopefully be mostly obsoleted as soon as we have generics. The set of methods is not in any way complete, because I only add what I just needed.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voiddelete(byte[] ary, int pos, int count) deletescountelements fromarystarting at indexposby copying the elements at indices greater than or equal topos+countto indexpos.static voiddelete(int[] ary, int pos, int count) deletescountelements fromarystarting at indexposby copying the elements at indices greater than or equal topos+countto indexpos.static voidstatic voidinsert(byte[] ary, int pos, byte elem) static voidinsert(char[] ary, int pos, char elem) static voidinsert(int[] ary, int pos, int elem) insertselemat indexposinaryby shifting all elements at indices greaterposto a one larger index position.static voidstatic byte[]resize(byte[] old, int newSize) static char[]resize(char[] old, int newSize) static int[]resize(int[] old, int newSize) allocates a new array with the givennewSizeand copies the content ofoldinto the new array up to the maximum ofnewSizeorold.length.static Object[]
-
Method Details
-
resize
public static int[] resize(int[] old, int newSize) allocates a new array with the given
newSizeand copies the content ofoldinto the new array up to the maximum ofnewSizeorold.length.- Returns:
- the newly allocate array
-
insert
public static void insert(int[] ary, int pos, int elem) insertselemat indexposinaryby shifting all elements at indices greaterposto a one larger index position. The very last element of the array is lost. -
delete
public static void delete(int[] ary, int pos, int count) deletes
countelements fromarystarting at indexposby copying the elements at indices greater than or equal topos+countto indexpos. The elements which become "free" at the end of the array are not touched and the array is not resized. Callresize()afterwards to reallocate the array. -
delete
public static void delete(byte[] ary, int pos, int count) deletes
countelements fromarystarting at indexposby copying the elements at indices greater than or equal topos+countto indexpos.- See Also:
-
resize
public static char[] resize(char[] old, int newSize) - See Also:
-
insert
public static void insert(char[] ary, int pos, char elem) - See Also:
-
resize
public static byte[] resize(byte[] old, int newSize) - See Also:
-
insert
public static void insert(byte[] ary, int pos, byte elem) - See Also:
-
resize
- See Also:
-
insert
- See Also:
-
delete
- See Also:
-