Package pi.util
Class ArrayUtil
java.lang.Object
pi.util.ArrayUtil
Utility class for array operations.
This class provides various static methods for manipulating arrays, such as concatenation, splitting, joining, and more.
Note: This class cannot be instantiated.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]append(T[] input, T addItem) Adds the specified item to the input array and returns a new array instance with the length of the input array +1.static <T> T[]arrayCopy(T[] original) Creates a copy of the specified array.static byte[]concat(byte[] first, byte[] second) Concatenates the two specified byte arrays to a new array.static double[]concat(double[] first, double[] second) Concatenates the two specified double arrays to a new array.static int[]concat(int[] first, int[] second) Concatenates the two specified int arrays to a new array.static long[]concat(long[] first, long[] second) Concatenates the two specified long arrays to a new array.static <T> T[]concat(T[] first, T[] second) Concatenates the two specified double arrays to a new array.static booleanReturn true if the array contains the specified value.static booleanReturn true if the array contains the specified string argument.static <T> T[]distinct(T[] first, T[] second) Combines the two specified arrays by only keeping distinct values.static Stringjoin(boolean[] arr) Joins the specified array with theDEFAULT_STRING_DELIMITER.static StringJoins the specified array with the defined delimiter.static Stringjoin(byte[] arr) Joins the specified array with theDEFAULT_STRING_DELIMITER.static StringJoins the specified array with the defined delimiter.static Stringjoin(double[] arr) Joins the specified array with theDEFAULT_STRING_DELIMITER.static StringJoins the specified array with the defined delimiter.static Stringjoin(float[] arr) Joins the specified array with theDEFAULT_STRING_DELIMITER.static StringJoins the specified array with the defined delimiter.static Stringjoin(int[] arr) Joins the specified array with theDEFAULT_STRING_DELIMITER.static StringJoins the specified array with the defined delimiter.static Stringjoin(long[] arr) Joins the specified array with theDEFAULT_STRING_DELIMITER.static StringJoins the specified array with the defined delimiter.static Stringjoin(short[] arr) Joins the specified array with theDEFAULT_STRING_DELIMITER.static Stringstatic StringJoins the specified array with theDEFAULT_STRING_DELIMITER.static StringJoins the specified array with the defined delimiter.static Stringjoin(Collection<?> collection) Joins the specified list with theDEFAULT_STRING_DELIMITER.static Stringjoin(Collection<?> collection, String delimiter) Joins the specified collection with the defined delimiter.static <T> T[]remove(T[] input, T deleteItem) Removes the specified deleteItem from the input array and returns a trimmed new array instance without null entries.static double[]splitDouble(String delimiterSeparatedString) Splits the specified string by theDEFAULT_STRING_DELIMITERinto a double array.static double[]splitDouble(String delimiterSeparatedString, String delimiter) Splits the specified string by the defined delimiter into a double array.static int[]Splits the specified string by theDEFAULT_STRING_DELIMITERinto an int array.static int[]Splits the specified string by the defined delimiter into an int array.static int[]toIntegerArray(List<Integer> intList) Converts a list of Integer objects to an array of primitive int values.static <T> List<T>toList(T[][] arr)
-
Field Details
-
DEFAULT_STRING_DELIMITER
- See Also:
-
-
Method Details
-
concat
public static byte[] concat(byte[] first, byte[] second) Concatenates the two specified byte arrays to a new array.- Parameters:
first- The first array.second- The second array.- Returns:
- A new array with both specified arrays in sequence.
-
concat
public static int[] concat(int[] first, int[] second) Concatenates the two specified int arrays to a new array.- Parameters:
first- The first array.second- The second array.- Returns:
- A new array with both specified arrays in sequence.
-
concat
public static long[] concat(long[] first, long[] second) Concatenates the two specified long arrays to a new array.- Parameters:
first- The first array.second- The second array.- Returns:
- A new array with both specified arrays in sequence.
-
concat
public static double[] concat(double[] first, double[] second) Concatenates the two specified double arrays to a new array.- Parameters:
first- The first array.second- The second array.- Returns:
- A new array with both specified arrays in sequence.
-
concat
public static <T> T[] concat(T[] first, T[] second) Concatenates the two specified double arrays to a new array.- Type Parameters:
T- The type of the array elements.- Parameters:
first- The first array.second- The second array.- Returns:
- A new array with both specified arrays in sequence.
-
splitInt
Splits the specified string by theDEFAULT_STRING_DELIMITERinto an int array.- Parameters:
delimiterSeparatedString- The string to split.- Returns:
- An int array with all separated elements of the specified string.
-
splitInt
Splits the specified string by the defined delimiter into an int array.- Parameters:
delimiterSeparatedString- The string to split.delimiter- The delimiter by which to split the elements.- Returns:
- An int array with all separated elements of the specified string.
-
splitDouble
Splits the specified string by theDEFAULT_STRING_DELIMITERinto a double array.- Parameters:
delimiterSeparatedString- The string to split.- Returns:
- A double array with all separated elements of the specified string.
-
splitDouble
Splits the specified string by the defined delimiter into a double array.- Parameters:
delimiterSeparatedString- The string to split.delimiter- The delimiter by which to split the elements.- Returns:
- A double array with all separated elements of the specified string.
-
join
Joins the specified array with theDEFAULT_STRING_DELIMITER.- Parameters:
arr- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with the defined delimiter.- Parameters:
arr- The array that provides the elements to be joined.delimiter- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with theDEFAULT_STRING_DELIMITER.- Parameters:
arr- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with the defined delimiter.- Parameters:
arr- The array that provides the elements to be joined.delimiter- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with theDEFAULT_STRING_DELIMITER.- Parameters:
arr- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with the defined delimiter.- Parameters:
arr- The array that provides the elements to be joined.delimiter- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with theDEFAULT_STRING_DELIMITER.- Parameters:
arr- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with the defined delimiter.- Parameters:
arr- The array that provides the elements to be joined.delimiter- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with theDEFAULT_STRING_DELIMITER.- Parameters:
arr- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
-
join
Joins the specified array with theDEFAULT_STRING_DELIMITER.- Parameters:
arr- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with the defined delimiter.- Parameters:
arr- The array that provides the elements to be joined.delimiter- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with theDEFAULT_STRING_DELIMITER.- Parameters:
arr- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with the defined delimiter.- Parameters:
arr- The array that provides the elements to be joined.delimiter- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified list with theDEFAULT_STRING_DELIMITER.- Parameters:
collection- The list that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified collection with the defined delimiter.- Parameters:
collection- The list that provides the elements to be joined.delimiter- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with theDEFAULT_STRING_DELIMITER.- Parameters:
arr- The array that provides the elements to be joined.- Returns:
- A string with all joined elements, separated by the delimiter.
-
join
Joins the specified array with the defined delimiter.- Parameters:
arr- The array that provides the elements to be joined.delimiter- The delimiter used to separate the elements with.- Returns:
- A string with all joined elements, separated by the delimiter.
-
toList
-
contains
Return true if the array contains the specified value.- Parameters:
arr- The array that is tested for the existence of the element.value- The element to check for in the array.- Returns:
- True if the specified element is in the array; otherwise false.
-
contains
Return true if the array contains the specified string argument.- Parameters:
arr- The array that is tested for the existence of the argument.argument- The argument to check for in the array.ignoreCase- A flag indicating whether the case should be ignored when checking for equality.- Returns:
- True if the specified argument is in the array; otherwise false.
-
remove
public static <T> T[] remove(T[] input, T deleteItem) Removes the specified deleteItem from the input array and returns a trimmed new array instance without null entries. The resulting array will have a length -1;- Type Parameters:
T- The element type of the array.- Parameters:
input- The original arraydeleteItem- The item to delete- Returns:
- A new array with the length input.length - 1.
-
append
public static <T> T[] append(T[] input, T addItem) Adds the specified item to the input array and returns a new array instance with the length of the input array +1.- Type Parameters:
T- The element type of the array.- Parameters:
input- The original array.addItem- The item to add.- Returns:
- A new array with the item to add appended at the end.
-
distinct
public static <T> T[] distinct(T[] first, T[] second) Combines the two specified arrays by only keeping distinct values.- Type Parameters:
T- The element type of the array.- Parameters:
first- The first array.second- The second array.- Returns:
- A new array with every distinct value of the specified arrays.
-
arrayCopy
public static <T> T[] arrayCopy(T[] original) Creates a copy of the specified array.- Type Parameters:
T- the type of the array elements- Parameters:
original- the array to copy- Returns:
- a new array that is a copy of the original array
-
toIntegerArray
Converts a list of Integer objects to an array of primitive int values.- Parameters:
intList- the list of Integer objects to convert- Returns:
- an array of primitive int values
-