Java Collection to String toString(Collection a, String begStr, String sepStr, String endStr)

Here you can find the source of toString(Collection a, String begStr, String sepStr, String endStr)

Description

to String

License

GNU General Public License

Declaration

public static <T> String toString(Collection<T> a, String begStr,
            String sepStr, String endStr) 

Method Source Code

//package com.java2s;
/*//from  w w  w .ja v a2s . co  m
 * Copyright (c) 2006-07, The Trustees of Stanford University.  All
 * rights reserved.
 * Licensed under the terms of the GNU GPL; see COPYING for details.
 */

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static <T> String toString(Collection<T> a, String begStr,
            String sepStr, String endStr) {
        int n = a.size();
        if (n == 0)
            return begStr + endStr;
        Iterator<T> it = a.iterator();
        String s = begStr + it.next();
        while (it.hasNext())
            s += sepStr + it.next();
        return s + endStr;
    }

    public static <T> String toString(Collection<T> a) {
        return toString(a, "", ",", "");
    }
}

Related

  1. toString(Collection itemList)
  2. toString(Collection objects, CharSequence delimiter)
  3. toString(Collection bytes, Collection result)
  4. toString(Collection collection)
  5. toString(Collection strings)
  6. toString(Collection collection)
  7. toString(Collection collection)
  8. toString(Collection collection)
  9. toString(Collection collection)

  10. HOME | Copyright © www.java2s.com 2016