Here you can find the source of concatenate(final Collection
Parameter | Description |
---|---|
objects | a parameter |
separator | a parameter |
static String concatenate(final Collection<String> objects, final String separator)
//package com.java2s; /******************************************************************************* * Manchester Centre for Integrative Systems Biology * University of Manchester/*from w w w . j av a2s . com*/ * Manchester M1 7ND * United Kingdom * * Copyright (C) 2007 University of Manchester * * This program is released under the Academic Free License ("AFL") v3.0. * (http://www.opensource.org/licenses/academic.php) *******************************************************************************/ import java.util.*; public class Main { /** * * @param objects * @param separator * @return String */ static String concatenate(final Collection<String> objects, final String separator) { final StringBuffer buffer = new StringBuffer(); if (objects != null) { for (Iterator<String> iterator = objects.iterator(); iterator.hasNext();) { buffer.append(iterator.next()); buffer.append(separator); } } // Strip out final separator: return concatenate(objects, null, separator); } /** * * @param objects * @param prefix * @param separator * @return String */ private static String concatenate(final Collection<String> objects, final String prefix, final String separator) { final StringBuffer buffer = new StringBuffer(); if (objects != null) { for (Iterator<String> iterator = objects.iterator(); iterator.hasNext();) { if (prefix != null) { buffer.append(prefix); } buffer.append(iterator.next()); buffer.append(separator); } } // Strip out final separator: return buffer.substring(0, (buffer.length() == 0) ? 0 : buffer.lastIndexOf(separator)); } }