Java Iterable Join join(String seperator, Iterator objects)

Here you can find the source of join(String seperator, Iterator objects)

Description

join

License

Apache License

Declaration

public static String join(String seperator, Iterator objects) 

Method Source Code


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

import java.util.*;

public class Main {
    public static String join(String seperator, String[] strings) {
        int length = strings.length;
        if (length == 0)
            return "";
        StringBuilder buf = new StringBuilder(length * strings[0].length()).append(strings[0]);
        for (int i = 1; i < length; i++) {
            buf.append(seperator).append(strings[i]);
        }/*from  w ww .  jav a2s  .  c  o  m*/
        return buf.toString();
    }

    public static String join(String seperator, Iterator objects) {
        StringBuilder buf = new StringBuilder();
        if (objects.hasNext())
            buf.append(objects.next());
        while (objects.hasNext()) {
            buf.append(seperator).append(objects.next());
        }
        return buf.toString();
    }

    public static String toString(Object[] array) {
        int len = array.length;
        if (len == 0)
            return "";
        StringBuilder buf = new StringBuilder(len * 12);
        for (int i = 0; i < len - 1; i++) {
            buf.append(array[i]).append(", ");
        }
        return buf.append(array[len - 1]).toString();
    }
}

Related

  1. join(String glue, Iterable tokens)
  2. join(String sep, Iterable strings)
  3. join(String separator, Iterable elements)
  4. join(String separator, Iterable objects)
  5. join(String separator, Iterable args)
  6. join(String seprator, Iterable coll)
  7. join(StringBuilder buf, Iterable values, String separator)
  8. joinIterableOnComma(Iterable iterable)
  9. joinIterables(final Iterable... iterables)