Binarray
A set of useful methods to work with arrays.
Before Using
You should consider the array and noElements as follows:
array = [a, b, c, d, e, null, null]
length = 7
noElements = 5
As you can see, the array is of size 7, however noElements is of size 5 since there are only 5 elements, also, all the elements must be concentrated in the left part of the array without null spaces. Otherwise, you will get various errors during execution.
Documentation Binarray
To String
(Binarray.toString(T[] array, int noElements) -> String)
Returns a String of an array's elements.
array: [a, b, c, null, null], noElements: 3 -> "[a, b, c]"
To String
(Binarray.toString(T[] array -> String)
Returns a String of an array's total elements (including null).
array: [a, b, c, d, null] -> "[a, b, c, d, null]"
Insert
(Binarray.insert(T value, T[] array, int noElements, int index) -> boolean)
Inserts an element in an array at an specified position and returns true if inserted correctly (noElements must be less than array.length).
value: d, array: [a, b, c, null], noElements: 3, index: 2 => [a, b, d, c] -> true
Delete
(Binarray.delete(T[] array, int noElements, int index) -> T)
Deletes an element in an array at an specified position and returns the element found.
array: [a, b, c, d, null], noElements: 4, index: 1 => [a, c, d, null, null] -> b
Max
(Binarray.max(T[] array, int noElements) -> int)
Returns the index of the greatest element of the array (T must extend Comparable).
array: [3, 6, 2, 4, null], noElements: 4 -> 1
Max
(Binarray.max(T[] array, int noElements, start) -> int)
Returns the index of the greatest element of the array from a starting position (T must extend Comparable).
array: [4, 8, 3, 7, 6, 5, null, null], noElements: 6, start: 2 -> 3
Min
(Binarray.min(T[] array, int noElements) -> int)
Returns the index of the smallest element of the array (T must extend Comparable).
array: [2, 5, 0, 1, null], noElements: 4 -> 2
Min
(Binarray.min(T[] array, int noElements, start) -> int)
Returns the index of the smallest element of the array from a position (T must extend Comparable).
[0, 2, 4, 5, 6, 1, null], noElements: 6, start: 1 -> 5
Traverse Left
(Binarray.traverseLeft(T[] array, int noElements, int index) -> boolean)
Traverse the elements of an array to the left from an index (index can't be last element).
array: [a, b, c, d, e, null], noElements: 5, index: 2 => [a, b, d, e, null, null] -> true
Traverse Right
(Binarray.traverseRight(T[] array, int noElements, int index) -> boolean)
Traverse the elements of an array to the right from an index (noElements must be less than array.length).
array: [a, b, d, e, null], noElements: 4, index: 2 => [a, b, null, d, e] -> true;
Reverse
(Binarray.reverse(T[] array) -> void)
Reverses an entire array (including nulls).
array: [a, b, c, d, e, null] => [null, e, d, c, b, a]
Reverse
(Binarray.reverse(T[] array, int noElements) -> void)
Reverses an array's elements.
array: [a, b, c, d, null], noElements: 4 => "[d, c, b, a, null]"
Clear
(Binarray.clear(T[]... arrays) -> void)
Sets in null all the arrays' array's spaces.
array: [a, b, c, d, null], [e, f] => [null, null, null, null, null], [null, null]
Fill
(Binarray.fill(T value, T[]... arrays) -> void)
Sets a value in all the arrays' array's spaces.
array: [a, b, c, d, null], [e, f, g], value: e => [e, e, e, e, e], [e, e, e]
Union
(Binarray.union(T[]... arrays) -> T[])
Returns a new array with the union of all arrays passed (ignoring all null elements).
arrays: [a, b, c, null], [c, d, null, e], [f, g] -> [a, b, c, d, e, f, g]
Intersection
(Binarray.intersection(T[]... arrays) -> T[])
Returns a new array with the intersection of all arrays passed (ignoring all null elements).
arrays: [a, b, null], [b, d, e], [b, e] -> [b]
Difference
(Binarray.difference(T[]... arrays)
Returns a new array with the difference of all arrays passed (ignoring all null elements).
arrays: [a, b, c, null, d, e], [d, e, f] -> [a, b, c, f]
Expand
(Binarray.expand(T[] array) -> T[])
Returns an expanded version (2 times bigger) of the array.
array: [a, b, c] -> [a, b, c, null, null, null]
Expand
(Binarray.expand(T[] array, int expand) -> T[])
Returns an expanded version (expand + array.length) of the array.
array: [a, b, c], expand = 2 -> [a, b, c, null, null]
Search
(Binarray.search(T value, T[] array, int noElements) -> int)
Returns the index where the value is found in the array, or -1 if it's not found.
value: b, array: [a, b, c, d, null] noElements: 4 -> 1
Search
(Binarray.search(T value, T[] array) -> int)
Returns the index where the value is found in the array, or -1 if it's not found (ignoring null elements).
value: c, array: [a, b, null, c, d, null]-> 3
Binary Search
(Binarray.binarySearch(T value, T[] array, int noElements) -> int)
Returns the index where the value is found in the array, or a negative of where should it be found. For this the array must be ordered from least to greatest (T must extend Comparable).
value: d, array: [a, b, c, d, null], noElements: 4 -> 3
Sort
(Binarray.sort(T[] array, int noElements) -> void)
Sorts the array from least to greatest (T must extend Comparable).
array: [c, b, d, a, null], noElements: 4 => [a, b, c, d, null]
Join
(Binarray.join(T[] array) -> String)
Returns the array as a joined string (including null).
array: ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', null] -> "Hello Worldnull"
Join
((Binarray.join(T[] array, int noElements) -> String)
Returns the array as a joined string.
array: ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', null], noElements: 11 -> "Hello World"
Join
(Binarray.join(T[] array, char regex) -> String)
Returns the array as a string with a char regex in between data (including null).
array: [a, b, c, d, null], regex: '-' -> "a-b-c-d-null"
Join
(Binarray.join(T[] array, int noElements, char regex) -> String)
Returns the array as a string with a char regex in between data.
array: [a, b, c, d, null], noElements: 4, regex: '-' -> "a-b-c-d"
Join
(Binarray.join(T[] array, String regex) -> String)
Returns the array as a string with a String regex in between data (including null).
array: [a, b, c, d, null], regex: " - " -> "a - b - c - d - null"
Join
(Binarray.join(T[] array, int noElements, String regex) -> String)
Returns the array as a string with a String regex in between data.
array: [a, b, c, d, null], noElements: 4, regex: " - " -> "a - b - c - d"