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

StringtoDelimitedString(final Collection coll, final String delim)
Convenience method to return a Collection as a delimited (e.g.
return tooDelimitedString(coll, delim, "", "");
ListtoDoubles(Collection numbers)
to Doubles
List<Double> result = new ArrayList<Double>();
for (Number number : numbers) {
    result.add(number.doubleValue());
return result;
EnumerationtoEnumeration(final Collection collection)
to Enumeration
return Collections.enumeration(collection);
StringtoEscapedStringWithDelimiters(Collection objects, String delim)
to Escaped String With Delimiters
StringBuffer buffer = new StringBuffer();
int index = 0;
for (Object obj : objects) {
    if (index++ > 0)
        buffer.append(delim);
    String string = obj.toString();
    if (string.startsWith("\"") && string.endsWith("\"")) {
        if (string.length() <= 2)
...
booleantoggleEntry(T entry, Collection collection)
Toggles an entry in a collection.
if (collection.remove(entry)) {
    return false;
} else {
    collection.add(entry);
    return true;
SettoHashSet(Collection c)
to Hash Set
if (isEmpty(c)) {
    return null;
Set<T> set = new HashSet<T>(c.size() * 2);
set.addAll(c);
return set;
StringtoHtml(Collection collection)
to Html
StringBuffer sb = new StringBuffer();
sb.append("<ul>");
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
    sb.append("<li>");
    sb.append(iterator.next());
    sb.append("</li>");
sb.append("</ul>");
return sb.toString();
CollectiontoIntegerCollection(int[] ints)
to Integer Collection
ArrayList<Integer> ret = new ArrayList<Integer>();
for (int i : ints)
    ret.add(new Integer(i));
return ret;
StringtoJSONString(Collection collection)
to JSON String
if (collection == null) {
    return null;
} else {
    StringBuilder sb = new StringBuilder();
    sb.append('[');
    for (Object item : collection) {
        if (item == null) {
            sb.append("null");
...
StringtokenSetString(Collection tokens)
token Set String
String string = String.join(", ", addNewLines(tokens));
if (tokens.size() < 5) {
    return string;
} else {
    return "\n" + string + "\n";