Java List Join join(final List things, final String on)

Here you can find the source of join(final List things, final String on)

Description

join

License

Apache License

Declaration

public static String join(final List<?> things, final String on) 

Method Source Code


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

import java.util.Iterator;
import java.util.List;

public class Main {
    public static String join(final List<?> things, final String on) {
        final StringBuilder sb = new StringBuilder();
        for (final Iterator<?> i = things.iterator(); i.hasNext();) {
            sb.append(i.next());//w w w .j a v a  2s. c o m
            if (i.hasNext()) {
                sb.append(on);
            }
        }
        return sb.toString();
    }

    public static String join(final Object[] things, final String on) {
        final StringBuilder sb = new StringBuilder();
        for (int i = 0, len = things.length; i < len; i++) {
            sb.append(things[i]);
            if (i < len - 1) {
                sb.append(on);
            }
        }
        return sb.toString();
    }
}

Related

  1. join(final List list, final String conjunction)
  2. join(final List toJoin)
  3. join(final List list, final CharSequence delim)
  4. join(final List args)
  5. join(final List list, final String separator)
  6. join(final List list, final String delimiter)
  7. join(final List array, final String separator)
  8. join(final List data, String separator)
  9. join(final List list)

  10. HOME | Copyright © www.java2s.com 2016