Java String Join joinString(String separator, String... elements)

Here you can find the source of joinString(String separator, String... elements)

Description

join String

License

Open Source License

Declaration

public static String joinString(String separator, String... elements) 

Method Source Code

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

import java.util.*;

public class Main {
    public static String joinString(String separator, String... elements) {
        return joinString(elements, separator);
    }//from  w ww.  ja  va  2 s .  c  o  m

    public static String joinString(Iterable<String> lines, String separator) {
        StringBuilder sb = new StringBuilder();
        for (String line : lines) {
            if (line != null) {
                sb.append(line);
                sb.append(separator);
            }
        }

        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1);
            return sb.toString();
        } else {
            return "";
        }
    }

    public static String joinString(String[] lines, String separator) {
        return joinString(Arrays.asList(lines), separator);
    }
}

Related

  1. JoinMaps(Map into, Map other)
  2. joinPath(String part1, String part2)
  3. joinPaths(String... paths)
  4. joinRepeat(int size, String s, String delim)
  5. joinSplit(String record, String regex)
  6. joinValues(Map map, String separator)
  7. joinWithSeparation(String a, String separator, String b)
  8. merge(ArrayList pArrayList, String pJoin)
  9. mergeDependencies(Set bundleDeps, List deps, Map disjointSets)