Java String to List stringToItems(List fontsList, boolean useSeparator)

Here you can find the source of stringToItems(List fontsList, boolean useSeparator)

Description

Convert a list of array of string into a single array of string, ready to be inserted into a combo

License

Open Source License

Parameter

Parameter Description
fontsList List of array of fonts (every list is a category)
useSeparator specify if a separator must be used between each category

Return

List of combo item

Declaration

public static String[] stringToItems(List<String[]> fontsList, boolean useSeparator) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (C) 2005 - 2014 TIBCO Software Inc. All rights reserved.
 * http://www.jaspersoft.com.//w  w  w  .  j a va 2s  . c om
 * 
 * Unless you have purchased  a commercial license agreement from Jaspersoft,
 * the following license terms  apply:
 * 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static String separator = "__________________";

    /**
     * Convert a list of array of string into a single array of string, ready to be inserted into a combo
     * 
     * @param fontsList
     *          List of array of fonts (every list is a category)
     * @param useSeparator
     *          specify if a separator must be used between each category
     * 
     * @return List of combo item
     */
    public static String[] stringToItems(List<String[]> fontsList, boolean useSeparator) {
        List<String> itemsList = new ArrayList<String>();
        for (int index = 0; index < fontsList.size(); index++) {
            String[] fonts = fontsList.get(index);
            for (String element : fonts)
                itemsList.add(element);
            if (index + 1 != fontsList.size() && fonts.length > 0 && useSeparator)
                itemsList.add(separator);
        }
        String[] result = new String[itemsList.size()];
        return itemsList.toArray(result);
    }

    /**
     * Convert a list of array of string into a single array of string, ready to be inserted into a combo
     * 
     * @param fontsList
     *          List of array of fonts, between every array will be inserted a separator
     * @return List of combo item
     */
    public static String[] stringToItems(List<String[]> fontsList) {
        return stringToItems(fontsList, true);
    }
}

Related

  1. convertToList(String[] array)
  2. stringsToList(final String[] src)
  3. stringToArrayList(String idString)
  4. stringToBooleanList(final String str, final boolean[] listData)
  5. stringToIntegerList(String input)
  6. stringToList(final String string)
  7. stringToList(String content)
  8. stringToList(String content, String splitter)
  9. stringToList(String delimitedString)