public class Collections2 extends Object
Constructor and Description |
---|
Collections2() |
Modifier and Type | Method and Description |
---|---|
static void |
fill(List in,
Object fill) |
static <T> T |
get(Collection<T> collection,
int i)
Gets the specific indexed element.
|
static int |
indexOf(List list,
Object o) |
static <T> String |
join(Collection<T> c,
Formatter<T> f,
String glue) |
static String |
join(Collection c,
Character glue) |
static String |
join(Collection c,
String glue) |
static String |
joinToString(List in,
String glue)
Deprecated.
since 2.5.0
|
static <T> T |
last(Collection<T> collection)
returns the last element of the collection.
|
static <T> T |
last(List<T> list)
returns the last element of the list.
|
static int |
max(Collection<? extends Comparable> in)
Find and return the index with the greatest value.
|
static <T> int |
max(Collection<T> in,
Comparator<T> comparator)
Find and return the index with the greatest value.
|
static <T extends Comparable> |
maxValue(Collection<T> in)
Find and return the object which is the max value
|
static double |
mean(Collection<? extends Number> list)
calculates the mean of all elements in the list
|
static int |
min(Collection<? extends Comparable> in)
Find and return the index with the smallest value.
|
static <T> int |
min(Collection<T> in,
Comparator<T> comparator)
Find and return the index with the greatest value.
|
static <T extends Comparable> |
minValue(Collection<T> in)
Find and return the object the is the max value
|
static <T> List<T> |
randomSample(Collection<T> in,
double ratio) |
static <T> List<T> |
randomSample(Collection<T> in,
int size)
returns a random sample from the input list
|
static <T> List<T> |
randomSample(Collection<T> in,
int size,
Random rnd)
returns a random sample from the input list
|
static double |
sum(Collection<? extends Number> list)
calculates the sum of all values in the list
|
static void |
trimToSize(Collection in,
int size) |
static <T> List<T> |
unique(Collection<T> src)
Returns a new List with unique elements from the source list.
|
static double |
variance(Collection<? extends Number> list)
calculates the variance of the elements in the list
|
public static <T> List<T> randomSample(Collection<T> in, int size)
T
- generic type paramin
- source listsize
- size of sampleNullPointerException
- if in = nullIllegalArgumentException
- if size > in.size()public static <T> List<T> randomSample(Collection<T> in, double ratio)
public static <T> List<T> randomSample(Collection<T> in, int size, Random rnd)
T
- generic type paramin
- source listsize
- size of samplernd
- Radnom generatorNullPointerException
- if in = nullIllegalArgumentException
- if size > in.size()public static void trimToSize(Collection in, int size)
public static <T> List<T> unique(Collection<T> src)
T
- type paramsrc
- input collectionpublic static String joinToString(List in, String glue)
in
- glue
- join(java.util.Collection, java.lang.String)
public static int max(Collection<? extends Comparable> in)
in
- the collection of objectspublic static <T extends Comparable> T maxValue(Collection<T> in)
T
- type paramin
- input datamax(java.util.Collection)
public static <T> int max(Collection<T> in, Comparator<T> comparator)
T
- type paramin
- the collection of objectscomparator
- which does the comparisonspublic static int min(Collection<? extends Comparable> in)
in
- input datapublic static <T extends Comparable> T minValue(Collection<T> in)
T
- type paramin
- input datamax(java.util.Collection)
public static <T> int min(Collection<T> in, Comparator<T> comparator)
T
- type paramin
- the collection of objectscomparator
- which does the comparisonspublic static double sum(Collection<? extends Number> list)
list
- input datapublic static double mean(Collection<? extends Number> list)
list
- input datapublic static double variance(Collection<? extends Number> list)
list
- input datapublic static <T> String join(Collection<T> c, Formatter<T> f, String glue)
public static String join(Collection c, Character glue)
public static String join(Collection c, String glue)
public static <T> T last(List<T> list)
T
- type paramlist
- input datapublic static <T> T last(Collection<T> collection)
T
- type paramcollection
- input datapublic static <T> T get(Collection<T> collection, int i)
T
- type paramcollection
- input datai
- index of the element (can also be negative, then it's addressed from the end)Copyright © 2015. All Rights Reserved.