Java Iterator 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.Iterator;

public class Main {
    public static String join(String seperator, String[] strings) {
        int length = strings.length;
        if (length == 0)
            return "";
        StringBuffer buf = new StringBuffer(length * strings[0].length()).append(strings[0]);
        for (int i = 1; i < length; i++) {
            buf.append(seperator).append(strings[i]);
        }/* ww w .j  a  v a  2s.co  m*/
        return buf.toString();
    }

    public static String join(String seperator, Iterator objects) {
        StringBuffer buf = new StringBuffer();
        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 "";
        StringBuffer buf = new StringBuffer(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(Iterator iterator, String separator)
  2. join(Iterator objects, String separator)
  3. join(Iterator iterator, String separator)
  4. join(Iterator iterator)
  5. join(String delimiter, Iterator iterator)
  6. join(String seperator, Iterator objects)
  7. joinIterators(final Iterator... iterators)