Java List Create createCommaList(List values, int rowCharacterCount)

Here you can find the source of createCommaList(List values, int rowCharacterCount)

Description

Gets the comma list for given values.

License

Apache License

Parameter

Parameter Description
values The values to handle as simple String
rowCharacterCount The row character number what will indicate the new line should be added

Return

The comma list for given values

Declaration

public static String createCommaList(List<?> values, int rowCharacterCount) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.*;

public class Main {
    /**/*from w ww  .  ja  v a  2 s.  c  om*/
     * Gets the comma list for given values.
     * 
     * @param values The values to handle as simple String
     * @param rowCharacterCount The row character number what will indicate the new line should be added
     * @return The comma list for given values
     */
    public static String createCommaList(List<?> values, int rowCharacterCount) {
        StringBuffer lSB = new StringBuffer();
        StringBuffer lRowSB = new StringBuffer();
        int liValuesCount = values.size();
        int li = 0;
        for (Object lValue : values) {
            lRowSB.append(lValue.toString());
            if (li < liValuesCount - 1) {
                lRowSB.append(", ");
            }
            if (lRowSB.length() > rowCharacterCount) {
                lSB.append(lRowSB);
                lSB.append("\r\n");
                lRowSB = new StringBuffer();
            }
            li++;
        }
        lSB.append(lRowSB);
        return lSB.toString();
    }

    /**
     * Gets the comma list for given values.
     * 
     * @param values  The values to handle as simple String
     * @return The comma list for given values
     */
    public static String createCommaList(List<?> values) {
        StringBuffer lSB = new StringBuffer();
        if (values != null) {
            for (Object lValue : values) {
                lSB.append(lValue.toString());
                lSB.append(", ");
            }
            if (lSB.length() > 0) {
                lSB.delete(lSB.length() - 2, lSB.length() - 1);
            }
        }
        return lSB.toString();
    }
}

Related

  1. createBVQueryParametersList()
  2. createCategoryName(List names)
  3. createChancePrefixList(List chances)
  4. createClassList(List objects)
  5. createColumnsToken(List columnnames)
  6. createCommand(LinkedList> list)
  7. createConflictMessage(List conflicts)
  8. createConfusionMatrix(HashMap> tempM, List actualLabelsList, List predictedLabelsList)
  9. createConsultInfoMap(List resAry)

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