Java ArrayList Join join(ArrayList list, String delimiter)

Here you can find the source of join(ArrayList list, String delimiter)

Description

join

License

Open Source License

Declaration

public static String join(ArrayList<String> list, String delimiter) 

Method Source Code


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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;

public class Main {
    public static String join(ArrayList<String> list, String delimiter) {
        StringBuilder stringBuilder = new StringBuilder();

        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            stringBuilder.append(iterator.next());
            if (!iterator.hasNext())
                break;
            stringBuilder.append(delimiter);
        }//from   www  . ja v a2 s.co m

        return stringBuilder.toString();
    }

    public static String join(String[] array, String delimiter) {
        return join(new ArrayList<String>(Arrays.asList(array)), delimiter);
    }
}

Related

  1. join(ArrayList list, String delimeter)
  2. join(ArrayList arr, String separator)
  3. Join(ArrayList coll, String delimiter)
  4. join(ArrayList list)
  5. Join(ArrayList list, String delimiter)
  6. join(ArrayList list, String joinChar)
  7. join(ArrayList nameList, String delimiter)
  8. join(ArrayList s, String delimiter)
  9. join(ArrayList strings, String separator)