Java Collection Join join(String token, Collection strings)

Here you can find the source of join(String token, Collection strings)

Description

join

License

Open Source License

Declaration

public static String join(String token, Collection strings) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    public static String join(String token, String[] strings) {
        StringBuffer sb = new StringBuffer();

        for (int x = 0; x < (strings.length - 1); x++) {
            sb.append(strings[x]);/*  ww  w  . j a  v  a  2s .c o m*/
            sb.append(token);
        }
        sb.append(strings[strings.length - 1]);

        return (sb.toString());
    }

    public static String join(String token, Collection strings) {
        StringBuffer sb = new StringBuffer();

        for (Iterator iter = strings.iterator(); iter.hasNext();) {
            sb.append(iter.next());
            if (iter.hasNext()) {
                sb.append(token);
            }
        }

        return (sb.toString());
    }
}

Related

  1. join(String separator, Collection list)
  2. join(String separator, Collection parts)
  3. join(String separator, Collection strings)
  4. join(String separator, Collection objects)
  5. join(String separator, Collection values)
  6. join(String[] collection, String delimiter)
  7. join(String[] collection, String separator)
  8. join(StringBuilder builder, Collection strs)
  9. join2(Collection list, String delimiter)