Convert Collection to String - Android java.util

Android examples for java.util:Collection Convert

Description

Convert Collection to String

Demo Code


//package com.java2s;

import java.util.Arrays;
import java.util.Collection;

import java.util.Iterator;

import android.hardware.Camera;

public class Main {
    private static String toString(Collection<int[]> arrays) {
        if (arrays == null || arrays.isEmpty()) {
            return "[]";
        }//from   w ww  . j a va  2 s. co m
        StringBuilder buffer = new StringBuilder();
        buffer.append('[');
        Iterator<int[]> it = arrays.iterator();
        while (it.hasNext()) {
            buffer.append(Arrays.toString(it.next()));
            if (it.hasNext()) {
                buffer.append(", ");
            }
        }
        buffer.append(']');
        return buffer.toString();
    }

    private static String toString(Iterable<Camera.Area> areas) {
        if (areas == null) {
            return null;
        }
        StringBuilder result = new StringBuilder();
        for (Camera.Area area : areas) {
            result.append(area.rect).append(':').append(area.weight)
                    .append(' ');
        }
        return result.toString();
    }
}

Related Tutorials