Java List to String toStringList(HashSet V)

Here you can find the source of toStringList(HashSet V)

Description

to String List

License

Apache License

Declaration

public static String toStringList(HashSet V) 

Method Source Code


//package com.java2s;
/*//w w  w .j av a  2s.c  om
Copyright 2001-2015 Bo Zimmerman
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    
   http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
 */

import java.util.*;

public class Main {
    public static String toStringList(String[] V) {
        if ((V == null) || (V.length == 0)) {
            return "";
        }
        final StringBuffer s = new StringBuffer("");
        for (final String element : V)
            s.append(", " + element);
        if (s.length() == 0)
            return "";
        return s.toString().substring(2);
    }

    public static String toStringList(long[] V) {
        if ((V == null) || (V.length == 0)) {
            return "";
        }
        final StringBuffer s = new StringBuffer("");
        for (final long element : V)
            s.append(", " + element);
        if (s.length() == 0)
            return "";
        return s.toString().substring(2);
    }

    public static String toStringList(int[] V) {
        if ((V == null) || (V.length == 0)) {
            return "";
        }
        final StringBuffer s = new StringBuffer("");
        for (final int element : V)
            s.append(", " + element);
        if (s.length() == 0)
            return "";
        return s.toString().substring(2);
    }

    public static String toStringList(Vector V) {
        if ((V == null) || (V.size() == 0)) {
            return "";
        }
        final StringBuffer s = new StringBuffer("");
        for (int v = 0; v < V.size(); v++)
            s.append(", " + V.elementAt(v).toString());
        if (s.length() == 0)
            return "";
        return s.toString().substring(2);
    }

    public static String toStringList(HashSet V) {
        if ((V == null) || (V.size() == 0)) {
            return "";
        }
        final StringBuffer s = new StringBuffer("");
        for (final Iterator i = V.iterator(); i.hasNext();)
            s.append(", " + i.next().toString());
        if (s.length() == 0)
            return "";
        return s.toString().substring(2);
    }

    public static String toStringList(Hashtable V) {
        if ((V == null) || (V.size() == 0)) {
            return "";
        }
        final StringBuffer s = new StringBuffer("");
        for (final Enumeration e = V.keys(); e.hasMoreElements();) {
            final String KEY = (String) e.nextElement();
            s.append(KEY + "=" + ((String) V.get(KEY)) + "/");
        }
        return s.toString();
    }
}

Related

  1. toStringList(Collection strings, String separator)
  2. toStringList(final double[] array)
  3. toStringList(final E[] array)
  4. toStringList(final List list)
  5. toStringList(final String tags)
  6. toStringList(List list)
  7. toStringList(List list)
  8. toStringList(List list)
  9. toStringList(List source)

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