Java Array Join join(String s[], String glue)

Here you can find the source of join(String s[], String glue)

Description

Join the given strings with given glue

License

Apache License

Parameter

Parameter Description
s a parameter
glue a parameter

Return

String

Declaration

public static String join(String s[], String glue) 

Method Source Code


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

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

public class Main {
    /**//from  w ww.jav a2 s  .  co m
     * Join the given strings with given glue
     *
     * @param   s
     * @param   glue
     * @return  String
     */
    public static String join(String s[], String glue) {
        StringBuilder buffer = new StringBuilder();
        List list = Arrays.asList(s);
        Iterator iterator = list.iterator();

        while (iterator.hasNext()) {
            buffer.append(iterator.next());
            if (iterator.hasNext())
                buffer.append(glue);
        }

        return buffer.toString();
    }
}

Related

  1. join(String delimiter, String[] elements)
  2. join(String delimiter, String[] s)
  3. join(String glue, String[] strings)
  4. join(String glue, String[] strings)
  5. join(String s, String[] arr, int off, int end)
  6. join(String sep, final String[] strings)
  7. join(String sep, Object[] os)
  8. join(String sep, String[] a)
  9. join(String sep, String[] arr)