join Iterable with delimiter - Android java.util

Android examples for java.util:Iterable

Description

join Iterable with delimiter

Demo Code


//package com.book2s;

import java.util.Iterator;

public class Main {
    public static String join(Iterable<?> pairs, String delimiter) {
        StringBuilder ret = new StringBuilder();
        Iterator<?> it = pairs.iterator();
        while (it.hasNext()) {
            ret.append(it.next());/*  ww  w  .  ja v a  2 s  .c  om*/
            if (it.hasNext()) {
                ret.append(delimiter);
            }
        }
        return ret.toString();
    }
}

Related Tutorials