Example #1
0
  public static String convertToStringWithSeparator(
      List<?> list, String separator, boolean withSpacing) {
    String result = "";

    if (CollectionUtil.isEmpty(list)) {
      return "";
    }

    for (Iterator<?> iterator = list.iterator(); iterator.hasNext(); ) {
      Object o = iterator.next();
      String s = o.toString();
      result += s;

      if (iterator.hasNext()) {
        if (withSpacing) result += ", ";
        else result += ",";
      }
    }

    return result;
  }