com.google.common.collect
Class PrimitiveArrays

java.lang.Object
  extended by com.google.common.collect.PrimitiveArrays

public final class PrimitiveArrays
extends Object

Static utility methods pertaining to arrays of Java primitives.

Author:
DJ Lee, Michael Parker

Method Summary
static List<Boolean> asList(boolean[] backingArray)
          Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...).
static List<Byte> asList(byte[] backingArray)
          Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...).
static List<Character> asList(char[] backingArray)
          Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...).
static List<Double> asList(double[] backingArray)
          Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...).
static List<Float> asList(float[] backingArray)
          Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...).
static List<Integer> asList(int[] backingArray)
          Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...).
static List<Long> asList(long[] backingArray)
          Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...).
static List<Short> asList(short[] backingArray)
          Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...).
static boolean[] toBooleanArray(Collection<Boolean> collection)
          Converts a Collection of Boolean instances (wrapper objects) into a new array of primitive booleans.
static byte[] toByteArray(Collection<Byte> collection)
          Converts a Collection of Byte instances (wrapper objects) into a new array of primitive bytes.
static char[] toCharArray(Collection<Character> collection)
          Converts a Collection of Character instances (wrapper objects) into a new array of primitive chars.
static double[] toDoubleArray(Collection<Double> collection)
          Converts a Collection of Double instances (wrapper objects) into a new array of primitive doubles.
static float[] toFloatArray(Collection<Float> collection)
          Converts a Collection of Float instances (wrapper objects) into a new array of primitive floats.
static int[] toIntArray(Collection<Integer> collection)
          Converts a Collection of Integer instances (wrapper objects) into a new array of primitive ints.
static long[] toLongArray(Collection<Long> collection)
          Converts a Collection of Long instances (wrapper objects) into a new array of primitive longs.
static short[] toShortArray(Collection<Short> collection)
          Converts a Collection of Short instances (wrapper objects) into a new array of primitive shorts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toShortArray

public static short[] toShortArray(Collection<Short> collection)
Converts a Collection of Short instances (wrapper objects) into a new array of primitive shorts.

Parameters:
collection - a Collection of Shorts.
Returns:
an array containing the same shorts as collection, in the same order, converted to primitives.

asList

public static List<Short> asList(short[] backingArray)
Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...). The only additional restriction of the returned list is that null cannot be assigned to any element via List.set(int,Object).

Parameters:
backingArray - the array to back the list
Returns:
a list view of the array

toIntArray

public static int[] toIntArray(Collection<Integer> collection)
Converts a Collection of Integer instances (wrapper objects) into a new array of primitive ints.

Parameters:
collection - a Collection of Integers.
Returns:
an array containing the same ints as collection, in the same order, converted to primitives.

asList

public static List<Integer> asList(int[] backingArray)
Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...). The only additional restriction of the returned list is that null cannot be assigned to any element via List.set(int,Object).

Parameters:
backingArray - the array to back the list
Returns:
a list view of the array

toDoubleArray

public static double[] toDoubleArray(Collection<Double> collection)
Converts a Collection of Double instances (wrapper objects) into a new array of primitive doubles.

Parameters:
collection - a Collection of Doubles.
Returns:
an array containing the same doubles as collection, in the same order, converted to primitives.

asList

public static List<Double> asList(double[] backingArray)
Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...). The only additional restriction of the returned list is that null cannot be assigned to any element via List.set(int,Object).

Parameters:
backingArray - the array to back the list
Returns:
a list view of the array

toFloatArray

public static float[] toFloatArray(Collection<Float> collection)
Converts a Collection of Float instances (wrapper objects) into a new array of primitive floats.

Parameters:
collection - a Collection of Floats.
Returns:
an array containing the same floats as collection, in the same order, converted to primitives.

asList

public static List<Float> asList(float[] backingArray)
Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...). The only additional restriction of the returned list is that null cannot be assigned to any element via List.set(int,Object).

Parameters:
backingArray - the array to back the list
Returns:
a list view of the array

toLongArray

public static long[] toLongArray(Collection<Long> collection)
Converts a Collection of Long instances (wrapper objects) into a new array of primitive longs.

Parameters:
collection - a Collection of Longs.
Returns:
an array containing the same longs as collection, in the same order, converted to primitives.

asList

public static List<Long> asList(long[] backingArray)
Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...). The only additional restriction of the returned list is that null cannot be assigned to any element via List.set(int,Object).

Parameters:
backingArray - the array to back the list
Returns:
a list view of the array

toCharArray

public static char[] toCharArray(Collection<Character> collection)
Converts a Collection of Character instances (wrapper objects) into a new array of primitive chars.

Parameters:
collection - a Collection of Characters.
Returns:
an array containing the same chars as collection, in the same order, converted to primitives.

asList

public static List<Character> asList(char[] backingArray)
Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...). The only additional restriction of the returned list is that null cannot be assigned to any element via List.set(int,Object).

Parameters:
backingArray - the array to back the list
Returns:
a list view of the array

toBooleanArray

public static boolean[] toBooleanArray(Collection<Boolean> collection)
Converts a Collection of Boolean instances (wrapper objects) into a new array of primitive booleans.

Parameters:
collection - a Collection of Booleans.
Returns:
an array containing the same booleans as collection, in the same order, converted to primitives.

asList

public static List<Boolean> asList(boolean[] backingArray)
Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...). The only additional restriction of the returned list is that null cannot be assigned to any element via List.set(int,Object).

Parameters:
backingArray - the array to back the list
Returns:
a list view of the array

toByteArray

public static byte[] toByteArray(Collection<Byte> collection)
Converts a Collection of Byte instances (wrapper objects) into a new array of primitive bytes.

Parameters:
collection - a Collection of Bytes.
Returns:
an array containing the same bytes as collection, in the same order, converted to primitives.

asList

public static List<Byte> asList(byte[] backingArray)
Returns a fixed-size list backed by the specified array, similar to Arrays.asList(T...). The only additional restriction of the returned list is that null cannot be assigned to any element via List.set(int,Object).

Parameters:
backingArray - the array to back the list
Returns:
a list view of the array