Java Collection Join join(String separator, Collection items)

Here you can find the source of join(String separator, Collection items)

Description

join

License

Open Source License

Declaration

public static String join(String separator, Collection<?> items) 

Method Source Code


//package com.java2s;
/*/*  ww  w . ja  v  a 2 s .  c om*/
Weave (Web-based Analysis and Visualization Environment)
Copyright (C) 2008-2011 University of Massachusetts Lowell
    
This file is a part of Weave.
    
Weave is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License, Version 3,
as published by the Free Software Foundation.
    
Weave is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.Collection;

public class Main {
    public static String join(String separator, Object[] items) {
        StringBuilder result = new StringBuilder((separator.length() + 1) * items.length);
        for (int i = 0; i < items.length; i++) {
            if (i > 0)
                result.append(separator);
            result.append(items[i].toString());
        }
        return result.toString();
    }

    public static String join(String separator, Collection<?> items) {
        StringBuilder result = new StringBuilder((separator.length() + 1) * items.size());
        int i = 0;
        for (Object item : items) {
            if (i > 0)
                result.append(separator);
            result.append(item.toString());
            i++;
        }
        return result.toString();
    }
}

Related

  1. join(String sep, Collection strings)
  2. join(String sep, Collection strs)
  3. join(String separator, Collection c)
  4. join(String separator, Collection c)
  5. join(String separator, Collection items)
  6. join(String separator, Collection objs)
  7. join(String separator, Collection list)
  8. join(String separator, Collection parts)
  9. join(String separator, Collection strings)