Java List to String listToString(List list, String separator)

Here you can find the source of listToString(List list, String separator)

Description

list To String

License

Open Source License

Declaration

public static String listToString(List<String> list, String separator) 

Method Source Code

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

import java.util.*;

public class Main {
    public static String listToString(List<String> list, String separator) {
        if (list.isEmpty()) {
            return "";
        }//from   w w w.  j  a v a 2  s. c om

        int n = list.size();
        StringBuilder sb = new StringBuilder();
        sb.append(list.get(0));
        if (n == 1) {
            return sb.toString();
        }

        for (int i = 1; i < n; i++) {
            sb.append(separator).append(list.get(i));
        }

        return sb.toString();
    }
}

Related

  1. listToString(List list)
  2. listToString(List list)
  3. listToString(List list)
  4. listToString(List list, String delimiter)
  5. listToString(List list, String expr)
  6. listToString(List list, String separator)
  7. listToString(List list, String separator)
  8. listToString(List list, String split)
  9. listToString(List params, String sepator)