# Class CollectionUtil

java.lang.Object
htsjdk.samtools.util.CollectionUtil

public class CollectionUtil extends Object
Small utility methods for dealing with collection classes.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static class`
`CollectionUtil.DefaultingMap<K,V>`
A defaulting map, which returns a default value when a value that does not exist in the map is looked up.
`static class`
`CollectionUtil.MultiMap<K,V>`
Simple multi-map for convenience of storing collections in map values.
`static class`
`CollectionUtil.Partitioner<V,K>`
Deprecated.
use Collectors.groupingBy instead

## Field Summary

Fields
Modifier and Type
Field
Description
`static final Comparator<Object>`
`OBJECT_TOSTRING_COMPARATOR`
Simple case-insensitive lexical comparator of objects using their `Object.toString()` value.

## Constructor Summary

Constructors
Constructor
Description
`CollectionUtil()`

## Method Summary

Modifier and Type
Method
Description
`static <T> T`
`getSoleElement(Collection<T> items)`
`static String`
`join(Collection<?> items, String inBetween)`
Construct a string by toString()ing each item in the collection with inBetween between each item.
`static <T> Collection<T>`
`makeCollection(Iterator<T> i)`
`static <T> List<T>`
`makeList(T... list)`
`static <T> Set<T>`
`makeSet(T... list)`
`static <K,V> Map<K, Collection<V>>`
`partition(Collection<V> collection, CollectionUtil.Partitioner<V,K> p)`
Deprecated.
use java8 .stream().collect(Collectors.groupingBy(()-> function)) instead
`static <K,V> Map<K, Collection<V>>`
`partition(Collection<V> collection, Function<? super V, ? extends K> keyer)`
Partitions a collection into groups based on a characteristics of that group.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### OBJECT_TOSTRING_COMPARATOR

public static final Comparator<Object> OBJECT_TOSTRING_COMPARATOR
Simple case-insensitive lexical comparator of objects using their `Object.toString()` value.

## Constructor Details

### CollectionUtil

public CollectionUtil()

## Method Details

### makeList

public static <T> List<T> makeList(T... list)

### makeSet

public static <T> Set<T> makeSet(T... list)

### makeCollection

public static <T> Collection<T> makeCollection(Iterator<T> i)

### join

public static String join(Collection<?> items, String inBetween)
Construct a string by toString()ing each item in the collection with inBetween between each item.

### getSoleElement

public static <T> T getSoleElement(Collection<T> items)

### partition

@Deprecated public static <K,V> Map<K, Collection<V>> partition(Collection<V> collection, CollectionUtil.Partitioner<V,K> p)
Deprecated.
use java8 .stream().collect(Collectors.groupingBy(()-> function)) instead
Partitions a collection into groups based on a characteristics of that group. Partitions are embodied in a map, whose keys are the value of that characteristic, and the values are the partition of elements whose characteristic evaluate to that key.

### partition

public static <K,V> Map<K, Collection<V>> partition(Collection<V> collection, Function<? super V, ? extends K> keyer)
Partitions a collection into groups based on a characteristics of that group. Partitions are embodied in a map, whose keys are the value of that characteristic, and the values are the partition of elements whose characteristic evaluate to that key.