Java List Join joinString(List array, String symbol)

Here you can find the source of joinString(List array, String symbol)

Description

join String

License

Apache License

Declaration

public static String joinString(List array, String symbol) 

Method Source Code

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

import java.util.*;

public class Main {

    public static String joinString(List array, String symbol) {
        String result = "";
        if (array != null) {
            for (int i = 0; i < array.size(); i++) {
                String temp = array.get(i).toString();
                if (temp != null && temp.trim().length() > 0)
                    result += (temp + symbol);
            }//  w  w w . jav  a2  s  . com
            if (result.length() > 1)
                result = result.substring(0, result.length() - 1);
        }
        return result;
    }

    public static String joinString(String[] array, String symbol) {
        String result = "";
        if (array != null) {
            for (int i = 0; i < array.length; i++) {
                String temp = array[i];
                if (temp != null && temp.trim().length() > 0)
                    result += (temp + symbol);
            }
            if (result.length() > 1)
                result = result.substring(0, result.length() - 1);
        }
        return result;
    }
}

Related

  1. joinNiceString(List strings)
  2. joinRecords(List first, List second, String key)
  3. joinRelativePath(List components)
  4. joinSegments(List segments, int startIndex, int endIndex)
  5. joinString(java.util.List values, String delimiter)
  6. joinString(List objs, String separator)
  7. joinString(List val, String delim)
  8. joinStringList(String delimiter, List stringList)
  9. joinStrings(Iterable list)