Java tutorial
//package com.java2s; import java.util.*; public class Main { private final static String LINE_SEPARATOR = System.getProperty("line.separator"); /** * returns a string where each object in the give {@code Collection} is placed on a new line * (i.e [foo, bar, bizz] -> <br/> foo <br/> bar <br/> bizz) * @param collection a given {@code Collection} of type {@code T} * @return */ public static <T> String lineSeparatedCollection(Collection<T> collection) { StringBuffer sb = new StringBuffer(""); for (T item : collection) { sb.append(item.toString()).append(LINE_SEPARATOR); } return sb.deleteCharAt(sb.lastIndexOf(LINE_SEPARATOR)).toString(); } /** * returns a string where each object in the give {@code Collection} is placed on a new line * (i.e [foo, bar, bizz] -> <br/> foo <br/> bar <br/> bizz) * @param collection a given {@code Array} of type {@code T} * @return */ public static <T> String lineSeparatedCollection(T... collection) { StringBuffer sb = new StringBuffer(""); for (T item : collection) { sb.append(item.toString()).append(LINE_SEPARATOR); } return sb.deleteCharAt(sb.lastIndexOf(LINE_SEPARATOR)).toString(); } }