Java Collection Flatten flatten(Collection collection, char separator)

Here you can find the source of flatten(Collection collection, char separator)

Description

flatten

License

Open Source License

Declaration

public static <T> String flatten(Collection<T> collection, char separator) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004-2010 Sunil Kamath (IcemanK).
 * All rights reserved.//from  www .j ava  2s.co  m
 * This program is made available under the terms of the Common Public License
 * v1.0 which is available at http://www.eclipse.org/legal/cpl-v10.html
 *
 * Contributors:
 *     Sunil Kamath (IcemanK) - initial API and implementation
 *******************************************************************************/

import java.util.*;

public class Main {
    public static <T> String flatten(Collection<T> collection, char separator) {
        StringBuilder buf = new StringBuilder(""); //$NON-NLS-1$
        if (!isEmptyCollection(collection)) {
            Iterator<T> iter = collection.iterator();
            buf.append(String.valueOf(iter.next()));
            while (iter.hasNext()) {
                buf.append(separator).append(String.valueOf(iter.next()));
            }
        }
        return buf.toString();
    }

    public static boolean isEmptyCollection(Collection<?> collection) {
        if (collection != null) {
            return collection.size() == 0;
        }
        return true;
    }
}

Related

  1. flatten(Collection> cols)
  2. flatten(Collection l)
  3. flatten(Collection list, Class type)
  4. flatten(Collection> nestedList)
  5. flatten(Collection> collOfLists)
  6. flatten(Collection original)
  7. flatten(final S targetCollection, final Collection> setOfSets)
  8. flattenCollection(Collection col)
  9. flattenCollection(Collection array, String fmt, char separator)