Java Vector to String convertVectorToString(Vector source, String separator)

Here you can find the source of convertVectorToString(Vector source, String separator)

Description

Convert the passed vector into a string with separators

License

Open Source License

Parameter

Parameter Description
source The Vector to convert
separator The separator to used

Return

String or null if source or separator not specified

Declaration

public static String convertVectorToString(Vector source,
        String separator) 

Method Source Code

//package com.java2s;
/* IBS Copyright/Security Notice ***************************************
 *                                              
 *  BAP Property of IBS AB//from   w w w . ja v  a  2 s  . c  o m
 *  (C) Copyright IBS AB 2001-2003
 *  All rights reserved.                        
 *  Use, duplication, or disclosure restricted  
 *  by license agreement with IBS AB.           
 *                                              
 *  Licensed Materials - Property of IBS AB     
 *                                              
 * End IBS Copyright/Security Notice **********************************
 *
 *
 * User  Date          Comment     
 * ---------------------------------------------------------------------
 * DMA   01/01/2000    Class created
 *  
 ***********************************************************************/

import java.util.*;

public class Main {
    /**
     * Convert the passed vector into a string with separators
     *
     * @param   source      The Vector to convert
     * @param   separator   The separator to used 
     * @return   String or null if source or separator not specified
     */
    public static String convertVectorToString(Vector source,
            String separator) {

        if (source == null || separator == null) {
            return null;
        }

        StringBuffer sb = new StringBuffer("");
        int si = source.size();
        for (int i = 0; i < si; i++) {
            sb.append(source.elementAt(i).toString());
            if ((i + 1) < si) {
                sb.append(separator);
            }
        }
        return sb.toString();
    }
}

Related

  1. convertVectorToStringArray(Vector vector)
  2. toStringArray(Vector V)
  3. vector2string(AbstractList v, String sep)
  4. vector2String(Vector v, String delimiter)