Java Collection to String buildString(Collection args, String seperator, int startingArg, int maxLength)

Here you can find the source of buildString(Collection args, String seperator, int startingArg, int maxLength)

Description

build String

License

Open Source License

Declaration

public static String buildString(Collection<String> args, String seperator, int startingArg, int maxLength) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main {
    public static String buildString(Collection<String> args, String seperator, int startingArg, int maxLength) {
        List<String> retList = new ArrayList<String>();
        String ret = "";
        for (int i = startingArg; i < args.size(); i++) {
            String s = (String) args.toArray()[i];
            ret += s + seperator;//from   w ww  . j av  a 2s .  c  o  m
            if (ret.length() > maxLength) {
                retList.add(ret);
                ret = "";
            }
        }
        retList.add(ret);
        ret = "";
        for (String s : retList) {
            ret += s + "\n";
        }
        if (ret.length() > 2) {
            ret = ret.substring(0, (ret.length() - seperator.length()) - 1);
        }
        return ret;
    }
}

Related

  1. asString(Collection c, String separator)
  2. asString(Collection collection)
  3. asStringArr(Collection collection)
  4. asStringArray(Collection coll)
  5. asStringArray(Collection collection)
  6. buildString(Collection keys)
  7. buildStringFromListForNuma(Collection list)
  8. collectionToCommaDelimitedString(Collection items)
  9. collectionToCommaDelimitedString(Collection list)