Java Iterable Join joinStr(CharSequence glue, Iterable parts)

Here you can find the source of joinStr(CharSequence glue, Iterable parts)

Description

join Str

License

LGPL

Declaration

public static String joinStr(CharSequence glue, Iterable<? extends CharSequence> parts) 

Method Source Code


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

import java.util.Iterator;

public class Main {
    public static String joinStr(CharSequence glue, Iterable<? extends CharSequence> parts) {
        return joinStr(glue, parts.iterator());
    }/*from   ww  w. j a  v a  2  s .  c  o  m*/

    public static String joinStr(CharSequence glue, Iterator<? extends CharSequence> parts) {
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;

        if (parts.hasNext()) {
            sb.append(parts.next());
        }
        while (parts.hasNext()) {
            sb.append(glue);
            sb.append(parts.next());
        }

        return sb.toString();
    }
}

Related

  1. join(String seperator, Iterator objects)
  2. join(String seprator, Iterable coll)
  3. join(StringBuilder buf, Iterable values, String separator)
  4. joinIterableOnComma(Iterable iterable)
  5. joinIterables(final Iterable... iterables)
  6. joinStrings(Iterable arr, String glue)
  7. joinStrings(Iterable strs, String sep)
  8. joinWith(Iterable elements, String join)