Java String Join joinRepeat(int size, String s, String delim)

Here you can find the source of joinRepeat(int size, String s, String delim)

Description

join Repeat

License

Apache License

Declaration

public static String joinRepeat(int size, String s, String delim) 

Method Source Code

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

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

public class Main {
    public static String joinRepeat(int size, String s, String delim) {
        return join(repeatList(size, s), delim);
    }//w w w.j av  a  2 s  . c o  m

    public static String join(Collection<?> s, String delimiter) {
        StringBuilder builder = new StringBuilder();
        Iterator iter = s.iterator();
        while (iter.hasNext()) {
            builder.append(iter.next().toString());
            if (!iter.hasNext()) {
                break;
            }
            builder.append(delimiter);
        }
        return builder.toString();
    }

    public static List<String> repeatList(int n, String s) {
        List<String> list = new ArrayList<String>();

        for (int i = 0; i < n; i++) {
            list.add(s);
        }

        return list;
    }
}

Related

  1. joinMap(Map map)
  2. joinMap(String keyValueSeperator, String recordSeperator, Map map)
  3. JoinMaps(Map into, Map other)
  4. joinPath(String part1, String part2)
  5. joinPaths(String... paths)
  6. joinSplit(String record, String regex)
  7. joinString(String separator, String... elements)
  8. joinValues(Map map, String separator)
  9. joinWithSeparation(String a, String separator, String b)