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

ObjectconvertToIntArray(Collection col)
convert To Int Array
int[] arr = new int[col.size()];
int pos = 0;
Iterator iter = col.iterator();
while (iter.hasNext()) {
    Number v = (Number) iter.next();
    arr[pos++] = v.intValue();
return arr;
...
T[]convertToPrimitive(Collection info)
convert To Primitive
return (T[]) info.toArray();
int[][]to2DIntArray(Collection coll)
to D Int Array
return (int[][]) coll.toArray(new int[coll.size()][]);
String[][]to2DStringArray(Collection coll)
to D String Array
return (String[][]) coll.toArray(new String[coll.size()][]);
IterabletoAlphaCollection(Collection collection)
to Alpha Collection
Iterator<U> it = collection.iterator();
List<U> list = new ArrayList<U>();
while (it.hasNext()) {
    list.add(it.next());
Collections.sort(list);
return list;
voidtoArray(Collection items, Object array[], boolean convert_to_primitive)
Put all of the elements in items into the given array This assumes that the array has been pre-allocated
assert (items.size() == array.length);
int i = 0;
for (T t : items) {
    if (convert_to_primitive) {
        if (t instanceof Long) {
            array[i] = ((Long) t).longValue();
        } else if (t instanceof Integer) {
            array[i] = ((Integer) t).intValue();
...
StringtoCollectionString(Collection c, char sep)
to Collection String
StringBuilder buf = new StringBuilder();
for (Object obj : c) {
    buf.append(obj).append(sep);
if (buf.length() > 0) {
    buf.setLength(buf.length() - 1);
return buf.toString();
...
StringtoCollectionString(Collection collection_p)
Return a string representation of the given collection which is typically suitable as a match ID representation
if (collection_p == null)
    return NULL;
StringBuilder builder = new StringBuilder();
builder.append('[');
Iterator<?> it = collection_p.iterator();
while (it.hasNext()) {
    Object element = it.next();
    String segment;
...
StringtoCommaDelimitedString(Collection c)
Returns the elements of c separated by commas.
return toDelimitedString(c, ", ");
StringtoCommaDelimitedStringInQuotes(Collection c)
Returns the elements of c separated by commas and enclosed in single-quotes
StringBuffer result = new StringBuffer();
for (Iterator i = c.iterator(); i.hasNext();) {
    Object o = i.next();
    result.append(",'" + o.toString() + "'");
return result.substring(1);