Java List Join joinStrings(List aList, String aString)

Here you can find the source of joinStrings(List aList, String aString)

Description

Returns a string by concatenating strings in given list separated by given string.

License

Open Source License

Declaration

public static String joinStrings(List aList, String aString) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    /**//from   w  w w  .ja  va2 s  .com
     * Returns a string by concatenating strings in given list separated by given string.
     */
    public static String joinStrings(List aList, String aString) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0, iMax = aList.size(); i < iMax; i++)
            sb.append(i == 0 ? "" : aString).append(aList.get(i));
        return sb.toString();
    }

    /**
     * Returns the size of a list (accepts null list).
     */
    public static int size(List aList) {
        return aList == null ? 0 : aList.size();
    }

    /**
     * Returns the object at the given index (returns null object for null list or invalid index).
     */
    public static <T> T get(List<T> aList, int anIndex) {
        return aList == null || anIndex < 0 || anIndex >= aList.size() ? null : aList.get(anIndex);
    }
}

Related

  1. joinString(List array, String symbol)
  2. joinString(List objs, String separator)
  3. joinString(List val, String delim)
  4. joinStringList(String delimiter, List stringList)
  5. joinStrings(Iterable list)
  6. joinStrings(List list, String delim)
  7. joinStrings(List strings, String separator)
  8. joinStrings(List strings, String separator)
  9. joinStrings(String delim, List strings)