Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class Main { public static Collection<String> addElementBeforeAndAfter(Collection<?> collection, String toAddBefore, String toAddAfter) { if (collection == null || collection.isEmpty()) { return Collections.emptyList(); } List<String> result = new ArrayList<>(collection.size()); for (Object o : collection) { StringBuilder stringBuilder = new StringBuilder( o.toString().length() + toAddBefore.length() + toAddAfter.length()); stringBuilder.append(toAddBefore); stringBuilder.append(o.toString().trim()); stringBuilder.append(toAddAfter); result.add(stringBuilder.toString()); } return result; } }