Example usage for java.util List toArray

List of usage examples for java.util List toArray

Introduction

In this page you can find the example usage for java.util List toArray.

Prototype

Object[] toArray();

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element).

Usage

From source file:Main.java

public static <T> T[] mergeArray(T t, T[] arrays) {
    List<T> newArrays = new ArrayList<T>();
    if (t != null) {
        newArrays.add(t);//ww w  .  j  av  a2s.  c o  m
    }
    if (arrays != null) {
        for (T e : arrays) {
            newArrays.add(e);
        }
    }
    return (T[]) newArrays.toArray();
}

From source file:Main.java

public static boolean getNextPermutation(StringBuilder sb) {
    List<Character> list = asList(sb.toString().toCharArray());
    boolean ret = getNextPermutation(list);

    Object[] array = list.toArray();
    sb.delete(0, sb.length());//ww w.j  ava 2  s . c  om
    sb.append(toCharArray(array));

    return ret;
}

From source file:com.iflytek.edu.cloud.frame.utils.ReflectionUtils.java

/**
 * ????,??./*w  w  w.  j  a  va 2  s .c  om*/
 *
 * @param collection     ???.
 * @param propertityName ??????.
 * @param separator      .
 */
public static String fetchElementPropertyToString(final Collection collection, final String propertyName,
        final String separator) throws Exception {
    List list = fetchElementPropertyToList(collection, propertyName);
    return StringUtils.join(list.toArray(), separator);
}

From source file:de.sub.goobi.metadaten.copier.ComposeFormattedRule.java

/**
 * The function typecast() converts the String arguments so that they can be
 * used by {@link String#format(String, Object...)}. Only arguments that are
 * referenced by number can be typecasted. If the format String contains
 * %2$02d?, the function will convert the second list object to long, if
 * the format String contains %02d? the function cannot tell which argument
 * is meant and thus doesnt do anything for it. TODO: check (test) and fix
 * it - especially catch continue//from   w  w w .  j  av  a  2 s.co  m
 *
 * @param format
 *            format String, to get the desired types from
 * @param elements
 *            arguments
 * @return the objects for the format command
 */
private static Object[] typecast(String format, List<String> elements) {
    Object[] result = elements.toArray();
    Matcher expressions = FORMAT_CODES_SCHEME.matcher(format);
    while (expressions.find()) {
        try {
            int i = Integer.parseInt(expressions.group(1)) - 1;
            switch (expressions.group(2).codePointAt(0)) {
            case 'A':
                result[i] = Double.parseDouble(elements.get(i));
                continue;
            case 'C':
                result[i] = Integer.parseInt(elements.get(i));
                continue;
            case 'E':
            case 'G':
                result[i] = Double.parseDouble(elements.get(i));
                continue;
            case 'T':
                result[i] = ISODateTimeFormat.dateElementParser().parseMillis(elements.get(i));
                continue;
            case 'X':
                result[i] = Long.parseLong(elements.get(i));
                continue;
            case 'a':
                result[i] = Double.parseDouble(elements.get(i));
                continue;
            case 'c':
                result[i] = Integer.parseInt(elements.get(i));
                continue;
            case 'd':
                result[i] = Long.parseLong(elements.get(i));
                continue;
            case 'e':
            case 'f':
            case 'g':
                result[i] = Double.parseDouble(elements.get(i));
                continue;
            case 'o':
                result[i] = Long.parseLong(elements.get(i));
                continue;
            case 't':
                result[i] = ISODateTimeFormat.dateElementParser().parseMillis(elements.get(i));
                continue;
            case 'x':
                result[i] = Long.parseLong(elements.get(i));
            }
        } catch (ArrayIndexOutOfBoundsException | ClassCastException | NumberFormatException e) {
        }
    }
    return result;
}

From source file:net.landora.video.utils.UIUtils.java

public static ComboBoxModel generateComboModel(List<?> parametersFor) {
    DefaultComboBoxModel model = new DefaultComboBoxModel(parametersFor.toArray());
    return model;
}

From source file:com.ibm.watson.developer_cloud.natural_language_classifier.v1.util.TrainingDataUtils.java

/**
 * Converts a training like argument list to a CSV representation.
 * //from   www. j av  a2s  .c  o  m
 * @param data
 *            the training data data
 * @return the string with the CSV representation for the training data
 */
public static String toCSV(final TrainingData... data) {
    Validate.notEmpty(data, "data cannot be null or empty");

    StringWriter stringWriter = new StringWriter();
    try {
        CSVPrinter printer = new CSVPrinter(stringWriter, CSVFormat.EXCEL);
        for (TrainingData trainingData : data) {
            if (trainingData.getText() == null || trainingData.getClasses() == null
                    || trainingData.getClasses().isEmpty())
                log.log(Level.WARNING, trainingData + " couldn't be converted to a csv record");
            else {
                List<String> record = new ArrayList<String>();
                record.add(trainingData.getText());
                record.addAll(trainingData.getClasses());
                printer.printRecord(record.toArray());
            }
        }
        printer.close();
    } catch (IOException e) {
        log.log(Level.SEVERE, "Error creating the csv", e);
    }

    return stringWriter.toString();
}

From source file:com.espertech.esperio.db.SupportDatabaseService.java

public static Object[][] readAll(String tableName) throws SQLException {
    Connection connection = getConnection(PARTURL, DBUSER, DBPWD);
    connection.setAutoCommit(true);/*from   w  w w  . j a va 2 s  . c o  m*/
    Statement stmt = connection.createStatement();
    String sql = "select * from " + tableName;
    log.info("Executing sql : " + sql);
    ResultSet resultSet = stmt.executeQuery(sql);

    List<Object[]> rows = new ArrayList<Object[]>();
    while (resultSet.next()) {
        List<Object> row = new ArrayList<Object>();
        for (int i = 0; i < resultSet.getMetaData().getColumnCount(); i++) {
            row.add(resultSet.getObject(i + 1));
        }
        rows.add(row.toArray());
    }

    Object[][] arr = new Object[rows.size()][];
    for (int i = 0; i < rows.size(); i++) {
        arr[i] = rows.get(i);
    }

    stmt.close();
    connection.close();
    return arr;
}

From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.framework.Util.java

public static <E> String listToString(List<E> list) {
    return arrayToString(list.toArray());
}

From source file:gov.nih.nci.caintegrator.application.lists.ajax.CommonListFunctions.java

public static String exportListasTxt(String name, HttpSession session) {
    String txt = "";
    UserListBeanHelper helper = new UserListBeanHelper(session);
    List<String> listItems = helper.getItemsFromList(name);
    txt = StringUtils.join(listItems.toArray(), "\r\n");
    return txt;// w w w  . java  2  s . com
}

From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.framework.Util.java

public static <E> boolean compareLists(List<E> l1, List<E> l2) {
    return compareArrays(l1.toArray(), l2.toArray());
}