public class MoreArrays
extends java.lang.Object
Constructor and Description |
---|
MoreArrays() |
Modifier and Type | Method and Description |
---|---|
static double |
computeSum(double[] d)
Computes the sum of the elements of d.
|
static int |
computeSum(int[] d)
Computes the sum of the elements of d.
|
static int[] |
doubleLengthOf(int[] a)
Returns an array twice the length of
a , with a copied into the first half of the new array. |
static java.lang.Object[] |
doubleLengthOf(java.lang.Object[] a)
Returns an array twice the length of
a with the same runtime type, with a copied into the first half of the
new array. |
static java.lang.String[] |
filterByKey(java.lang.String[] lines,
java.lang.String key)
Assumes that the input string array has at least two fields that are tab-delimited, and returns all fields beyond the 1st, where the
1st field matches the given key.
|
static java.lang.String |
intArrayToString(int[] a)
Returns a string version of an int array with the ints separated by commas.
|
static int[] |
integersToInts(java.lang.Integer[] input)
Converts the Integers to ints.
|
static <T extends java.lang.Comparable<T>> |
merge(java.lang.Object[] destn,
T[] src1,
T[] src2)
Merges src1 and src2 into destn, without any duplicates.
|
static int[] |
mergeSortedArrays(int[] a1,
int[] a2)
Returns a sorted array of the elements in a1 and a2, without any duplicates; a1 and a2 must both be sorted arrays.
|
static int[] |
randomIntArray(int min,
int max,
int count)
Returns an array of random ints in no particular order.
|
static int[] |
removeDuplicates(int[] a)
Returns a sorted version of
a without duplicates; requires the input array to be sorted. |
static java.lang.Object[] |
removeDuplicates(java.lang.Object[] a)
Returns a sorted version of
a with the same runtime type, with no duplicates; requires the input array to be sorted. |
static double[] |
resize(double[] a,
int i)
Returns a new array of length i containing the first i elements of a.
|
static int[] |
resize(int[] a,
int i)
Returns a new array of length i containing the first i elements of a.
|
static java.lang.Object[] |
resize(java.lang.Object[] a,
int i)
Returns a new array of length i containing the first i elements of a and having the same runtime type.
|
static void |
shuffle(int[] arr)
Randomly rearranges the contents of an array.
|
static void |
shuffle(java.lang.Object[] arr)
Randomly rearranges the contents of an array.
|
static java.lang.Object[] |
sortAndRemoveDuplicates(java.lang.Object[] input)
Sorts an array and removes duplicates, assuming that compareTo() is consistent with equals() for the input objects; the array returned
has the same runtime type as input.
|
static java.lang.Integer[] |
stringsToIntegers(java.lang.String[] lines)
Converts all the lines to Integers, ignoring non-integer lines.
|
private static void |
swap(int[] arr,
int i,
int j) |
private static void |
swap(java.lang.Object[] arr,
int i,
int j) |
static java.util.Hashtable<java.lang.String,java.lang.String> |
toHashtable(java.lang.String[] lines)
Takes a string array of two fields and separates each entry into a hashtable entry, where the first field is the key and the second
field is the value.
|
public static double computeSum(double[] d)
public static int computeSum(int[] d)
public static int[] doubleLengthOf(int[] a)
a
, with a
copied into the first half of the new array.public static java.lang.Object[] doubleLengthOf(java.lang.Object[] a)
a
with the same runtime type, with a
copied into the first half of the
new array.public static java.lang.String[] filterByKey(java.lang.String[] lines, java.lang.String key)
public static java.lang.String intArrayToString(int[] a)
public static int[] integersToInts(java.lang.Integer[] input)
public static <T extends java.lang.Comparable<T>> void merge(java.lang.Object[] destn, T[] src1, T[] src2)
public static int[] mergeSortedArrays(int[] a1, int[] a2)
public static int[] randomIntArray(int min, int max, int count)
public static int[] removeDuplicates(int[] a)
a
without duplicates; requires the input array to be sorted.public static java.lang.Object[] removeDuplicates(java.lang.Object[] a)
a
with the same runtime type, with no duplicates; requires the input array to be sorted.
Note that equivalence is determined here using .equals() and NOT .compareTo().
public static double[] resize(double[] a, int i)
public static int[] resize(int[] a, int i)
public static java.lang.Object[] resize(java.lang.Object[] a, int i)
public static void shuffle(int[] arr)
public static void shuffle(java.lang.Object[] arr)
public static java.lang.Object[] sortAndRemoveDuplicates(java.lang.Object[] input)
Note that equivalence is determined here using .equals() and NOT .compareTo().
public static java.lang.Integer[] stringsToIntegers(java.lang.String[] lines)
private static void swap(int[] arr, int i, int j)
private static void swap(java.lang.Object[] arr, int i, int j)
public static java.util.Hashtable<java.lang.String,java.lang.String> toHashtable(java.lang.String[] lines)