Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Anthony Eden http://allthings.mp/

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Join in Java

Join a collection of objects into a String using the specified delimiter. One thing to note is that the collection can contain any object. The object's toString() method will be used to convert said object to its String representation.

    public static String join(Collection s, String delimiter) {
        StringBuffer buffer = new StringBuffer();
        Iterator iter = s.iterator();
        while (iter.hasNext()) {
            buffer.append(iter.next());
            if (iter.hasNext()) {
                buffer.append(delimiter);
            }
        }
        return buffer.toString();
    }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS