Java Utililty Methods Iterable to String

List of utility methods to do Iterable to String

Description

The list of methods to do Iterable to String are organized into topic(s).

Method

StringiterableAsString(Iterable chars)
Convert an Iterable of Character s to String.
StringBuilder builder = new StringBuilder();
for (Character c : chars) {
    builder.append(c);
return builder.toString();
StringiterableToString(Iterable iterable)
This method will format any iterable class into a simple newline delimited list.
StringBuilder builder = new StringBuilder();
for (Object obj : iterable) {
    builder.append(String.format("%s\n", obj.toString()));
return builder.toString();
StringiterableToString(Iterable list)
iterable To String
if (list == null) {
    return "";
StringBuilder sb = new StringBuilder();
for (Object item : list) {
    sb.append(item);
    sb.append(",");
if (sb.length() > 0) {
    sb.deleteCharAt(sb.length() - 1);
return sb.toString();
StringiterableToString(Iterable charSequenceIterable)
iterable To String
StringBuilder sb = new StringBuilder("[");
for (Iterator<CharSequence> iterator = charSequenceIterable.iterator(); iterator.hasNext();) {
    CharSequence charSequence = iterator.next();
    sb.append(charSequence);
    if (iterator.hasNext()) {
        sb.append(", ");
sb.append("]");
return sb.toString();
StringiterableToString(Iterable itrbl)
iterable To String
StringBuffer buff = new StringBuffer();
buff.append("[ ");
boolean first = true;
for (E elem : itrbl) {
    if (!first) {
        buff.append(", ");
    first = false;
...
StringiterableToString(Iterable objects, int limit)
Returns a string representation of the iterable objects.
StringBuilder builder = new StringBuilder().append("[");
String sep = "";
int head = (limit <= 0) ? Integer.MAX_VALUE : (limit + 1) / 2;
int tail = (limit <= 0) ? 0 : limit - head;
Iterator<T> iter = objects.iterator();
while (iter.hasNext() && --head >= 0) {
    builder.append(sep).append(iter.next().toString());
    sep = ", ";
...
StringtoString(final Iterable iterable, final CharSequence delimiter)
Converts an iterable to a delimited string.
final StringBuilder result = new StringBuilder();
final Iterator<?> iterator = iterable.iterator();
while (iterator.hasNext()) {
    result.append(iterator.next());
    if (iterator.hasNext()) {
        result.append(delimiter);
return result.toString();
StringtoString(Iterable c, String delim, String prefix, String suffix)
to String
if (c == null) {
    return "null";
StringBuffer sb = new StringBuffer();
Iterator it = c.iterator();
int i = 0;
while (it.hasNext()) {
    if (i++ > 0) {
...
StringtoString(Iterable objects, String sep)
Returns a string that contains all objects separated with the given separator.
StringBuilder builder = new StringBuilder();
Iterator<? extends Object> it = objects.iterator();
if (it.hasNext()) {
    builder.append(it.next());
    while (it.hasNext()) {
        builder.append(sep);
        builder.append(it.next());
return builder.toString();
StringtoString(Iterable it, String separator)
to String
final StringBuilder builder = new StringBuilder();
final Iterator<?> iterator = it.iterator();
while (iterator.hasNext()) {
    builder.append(iterator.next().toString());
    if (iterator.hasNext()) {
        builder.append(separator);
return builder.toString();