Java Collection Concatenate concatEntries(Collection coll, String sep, String lastSep)

Here you can find the source of concatEntries(Collection coll, String sep, String lastSep)

Description

concat Entries

License

Apache License

Declaration

public static String concatEntries(Collection<?> coll, String sep, String lastSep) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static String concatEntries(Collection<?> coll, String sep, String lastSep) {
        if (lastSep == null) {
            lastSep = sep;//from w w  w .  jav  a 2  s  .  c o m
        }
        int len = coll.size();
        StringBuilder sb = new StringBuilder(16 + (len << 3));
        Iterator<?> it = coll.iterator();
        int i = 0;
        while (it.hasNext()) {
            if (i == 0) {
                ;
            } else if (i == (len - 1)) {
                sb.append(lastSep);
            } else {
                sb.append(sep);
            }
            ++i;
            sb.append(it.next());
        }
        return sb.toString();
    }
}

Related

  1. concatenate(Collection list)
  2. concatenate(final Collection objects, final String separator)
  3. concatenatedLTL(Collection ltl)
  4. concatenateIds(final Collection ids)
  5. concatenateWithComma(Collection collection)
  6. concatInt(Collection collection)
  7. concatNames(Collection cNames, String split)
  8. concatNumber(Collection keys)
  9. concatStrings(Collection strings)