Java Utililty Methods Collection Convert

List of utility methods to do Collection Convert

Description

The list of methods to do Collection Convert are organized into topic(s).

Method

TreeSettoTreeSet(Collection collection, Comparator comparator)
to Tree Set
final TreeSet<T> treeSet = new TreeSet<T>(comparator);
for (T t : collection) {
    treeSet.add(t);
return treeSet;
AnyCollectiontoUnmodifiableCollection( AnyCollection collection)
Transforms the collection to an unmodifiable one, if there is any implementation in the Java Collections utilities.
if (collection == null) {
    return null;
if (collection instanceof List<?>) {
    return (AnyCollection) Collections.unmodifiableList((List<?>) collection);
if (collection instanceof NavigableSet<?>) {
    return (AnyCollection) Collections.unmodifiableNavigableSet((NavigableSet<?>) collection);
...
CollectiontrimCollection(Collection collectionToBeConverted)
trim Collection
Collection convertCaseValues = new ArrayList<String>(collectionToBeConverted.size());
for (Iterator<String> iterator = collectionToBeConverted.iterator(); iterator.hasNext();) {
    String s = iterator.next();
    convertCaseValues.add(s.trim());
return convertCaseValues;