View Javadoc

1   package nl.toolforge.core.util.collection;
2   
3   import java.util.Collection;
4   import java.util.Iterator;
5   
6   /***
7    * Some utils. I reckon this sort of thing already exists. Just too lazy to look for it now.
8    *
9    * @author D.A. Smedes
10   * @version $Id: CollectionUtil.java,v 1.1 2004/09/13 19:36:55 asmedes Exp $
11   */
12  public final class CollectionUtil {
13  
14    /***
15     * Given a collection of <code>String</code> objects (determines runtime ...), this method returns a
16     * <code>String</code>, separated by a separator character. After the last String in the collection, no separator
17     * char is placed.
18     *
19     * @param collection
20     * @return
21     */
22    public static String concat(Collection collection, char separatorChar) {
23  
24      String s = "";
25  
26      for (Iterator i = collection.iterator(); i.hasNext();) {
27  
28        s += (String) i.next();
29  
30        if (i.hasNext()) {
31          s += separatorChar;
32        }
33      }
34      return s;
35    }
36  
37  }