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

<T> T[] toArray(T[] a);

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:Main.java

public static Method[] getMethodsByName(Class<?> clazz, String name) {
    Method[] methods = clazz.getMethods();
    List<Method> list = new ArrayList<Method>();

    for (Method method : methods) {
        if (method.getName().equals(name))
            list.add(method);/*ww w  .ja va  2  s .  co  m*/
    }

    return list.toArray(new Method[list.size()]);
}

From source file:com.github.liyp.test.TestMain.java

public static String[] splitAndTrim(String commaStr, String regex) {
    List<String> list = new ArrayList<>();
    for (String item : commaStr.split(",")) {
        list.add(item.trim());/*from   ww w . j  a v  a 2  s. c o  m*/
    }
    return list.toArray(new String[0]);
}

From source file:com.spotify.annoy.jni.base.AnnoyIndexImpl.java

private static float[] boxedToPrimitive(List<Float> vector) {
    return ArrayUtils.toPrimitive(vector.toArray(new Float[0]));
}

From source file:Main.java

public static String[] extractTags(String source) {
    final List<String> result = new LinkedList<String>();
    for (String tag : source.split(",")) {
        if (tag.trim().length() > 0)
            result.add(tag.trim());/* w  ww  .j a va  2s  .  co m*/
    }
    return result.toArray(new String[result.size()]);
}

From source file:at.medevit.elexis.gdt.handler.GDTFileInputHandler.java

public static String[] readFileGetUTF8(File file) {
    int encoding = GDTConstants.ZEICHENSATZ_IBM_CP_437;
    try {//from   w w w  .j a  v a2 s  . c o  m
        List<String> dataList = FileUtils.readLines(file, "cp437");
        String[] data = dataList.toArray(new String[] {});
        String usedEncoding = GDTSatzNachrichtHelper
                .getValueIfExists(GDTConstants.FELDKENNUNG_VERWENDETER_ZEICHENSATZ, data);
        if (usedEncoding == null)
            return data; // Not set return default encoding

        int usedEncodingInt = Integer.parseInt(usedEncoding);
        if (encoding == usedEncodingInt)
            return data; // Set, but default

        if (usedEncodingInt == GDTConstants.ZEICHENSATZ_7BIT) {
            return FileUtils.readLines(file, GDTConstants.ZEICHENSATZ_7BIT_CHARSET_STRING)
                    .toArray(new String[] {});
        } else if (usedEncodingInt == GDTConstants.ZEICHENSATZ_ISO8859_1_ANSI_CP_1252) {
            return FileUtils.readLines(file, "Cp1252").toArray(new String[] {});
        }
    } catch (IOException e) {
        String message = "GDT: Ein-/Ausgabe Fehler beim Lesen von " + file.getAbsolutePath();
        Status status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, message, e);
        StatusManager.getManager().handle(status, StatusManager.SHOW);
        logger.log(e, message, Log.WARNINGS);
    }
    return null;
}

From source file:Main.java

/**
 * This method returns an array of nodes that match the passed on criteria.
 * //from  w  w w.ja  v a  2  s  . c  o  m
 * @param eRoot The root element.
 * @param sPath The XPath to execute.
 * @return The array of nodes.
 */
public static Node[] match(Element eRoot, String sPath) {
    try {
        NodeIterator niIter = (NodeIterator) s_mSelectNodeIterator.invoke(null, new Object[] { eRoot, sPath });
        Node nNode;
        List<Node> lResList = new ArrayList<Node>(128);

        while ((nNode = niIter.nextNode()) != null) {
            lResList.add(nNode);
        }

        return lResList.toArray(new Node[lResList.size()]);
    } catch (Exception ignored) {
        return new Element[0];
    }
}

From source file:de.hsheilbronn.mi.process.AbstractSvmTool.java

public static svm_parameter unwrap(SvmConfiguration configuration) {
    svm_parameter param = new svm_parameter();

    param.svm_type = configuration.getSvmType().getNumericType();
    param.kernel_type = configuration.getKernelType().getNumericType();
    param.degree = configuration.getDegree();
    param.gamma = configuration.getGamma();
    param.coef0 = configuration.getCoef0();
    param.nu = configuration.getNu();/* www  .j a va 2s .c o  m*/
    param.cache_size = configuration.getCacheSize();
    param.C = configuration.getCost();
    param.eps = configuration.getEps();
    param.p = configuration.getP();
    param.shrinking = configuration.getShrinking();
    param.probability = configuration.getProbability();
    param.nr_weight = configuration.getNrWeight();

    List<Integer> weightLabel = configuration.getWeightLabel();

    param.weight_label = ArrayUtils.toPrimitive(weightLabel.toArray(new Integer[weightLabel.size()]));
    List<Double> weight = configuration.getWeight();

    param.weight = ArrayUtils.toPrimitive(weight.toArray(new Double[weight.size()]));

    if (configuration.isQuietMode()) {
        svm.svm_set_print_string_function(new svm_print_interface() {
            @Override
            public void print(String s) {
                //nothing to do here...
            }
        });
    }
    return param;
}

From source file:com.axibase.tsd.driver.jdbc.strategies.Consumer.java

private static void fillWarnings(List<WarningSection> warningSections, StatementContext context) {
    if (warningSections != null) {
        for (AtsdExceptionRepresentation section : warningSections) {
            SQLWarning sqlw = new SQLWarning(section.getMessage(), section.getState());
            List<StackTraceElement> list = getStackTrace(section);
            sqlw.setStackTrace(list.toArray(new StackTraceElement[list.size()]));
            context.addWarning(sqlw);/*w ww . j  av  a  2s  . co  m*/
        }
    }
}

From source file:Main.java

public static String[] arrayUnique(String[] a) {
    // array_unique
    List<String> list = new LinkedList<String>();
    for (int i = 0; i < a.length; i++) {
        if (!list.contains(a[i])) {
            list.add(a[i]);//from   w  w w.  ja v a2s.  c  o  m
        }
    }
    return (String[]) list.toArray(new String[list.size()]);
}

From source file:Main.java

/**
 * @return all the Strings in the array words which are present in the Set filter
 *//*from w  ww.  j ava2 s .  co  m*/
static String[] filter(String[] words, Set<String> filter) {
    if (words == null)
        return new String[0];
    List<String> filteredWords = new ArrayList<>();
    for (String word : words) {
        if (filter.contains(word))
            filteredWords.add(word);
    }
    return filteredWords.toArray(new String[filteredWords.size()]);
}