Example usage for java.util ArrayList toArray

List of usage examples for java.util ArrayList toArray

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public <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:Transform.java

/**
 * convert a Throwable into an array of Strings
 * @param throwable/*from www. ja v a 2  s.  co m*/
 * @return string representation of the throwable
 */
public static String[] getThrowableStrRep(Throwable throwable) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    throwable.printStackTrace(pw);
    pw.flush();
    LineNumberReader reader = new LineNumberReader(new StringReader(sw.toString()));
    ArrayList<String> lines = new ArrayList<String>();
    try {
        String line = reader.readLine();
        while (line != null) {
            lines.add(line);
            line = reader.readLine();
        }
    } catch (IOException ex) {
        lines.add(ex.toString());
    }
    String[] rep = new String[lines.size()];
    lines.toArray(rep);
    return rep;
}

From source file:com.prowidesoftware.swift.utils.TestUtils.java

/**
 * Returns the array of tags enclosed in 16RS with the given qualifier
 * @param startEnd16rs qualifier for 16RS tag
 * @param tags tags to include/*from   www.jav  a 2s. co m*/
 * @return the created array of tags
 * @deprecated use directly MTXXX.SequenceX.newInstance(Tag ...)
 */
@Deprecated
public static Tag[] newSeq(final String startEnd16rs, final Tag... tags) {
    final ArrayList<Tag> result = new ArrayList<Tag>();
    result.add(new Tag("16R", startEnd16rs));
    if (tags != null && tags.length > 0) {
        for (final Tag t : tags) {
            result.add(t);
        }
    }
    result.add(new Tag("16S", startEnd16rs));
    return (Tag[]) result.toArray(new Tag[result.size()]);
}

From source file:Main.java

@Deprecated
private static Long[] getIdArray(String serializedTree) {
    ArrayList<Long> ids = new ArrayList<>();
    String[] digitsOnly = serializedTree.split("[\\[\\],\\s]"); // Split on [ ] , or whitespace chars
    for (String idString : digitsOnly) {
        try {//from   ww  w. j  ava 2 s  . c o m
            if (!TextUtils.isEmpty(idString)) {
                ids.add(Long.parseLong(idString));
            }
        } catch (NumberFormatException e) {
            Log.e("widget-subtasks", "error parsing id " + idString, e);
        }
    }
    return ids.toArray(new Long[ids.size()]);
}

From source file:Main.java

public static Node[] getChildNodes(final Node node, final String elementName) {
    final ArrayList nodeList = new ArrayList();
    final NodeList childs = node.getChildNodes();
    String nodeName = null;//  w  w w. j a v a2  s .com
    for (int i = 0; i < childs.getLength(); i++) {
        nodeName = childs.item(i).getNodeName();
        if (nodeName != null && nodeName.equals(elementName)) {
            nodeList.add(childs.item(i));
        }
    } //next child node
    final Node[] result = new Node[nodeList.size()];
    nodeList.toArray(result);
    return result;
}

From source file:com.opengamma.util.test.DbTest.java

protected static Object[][] getParameters() {
    String databaseType = System.getProperty("test.database.type");
    if (databaseType == null) {
        databaseType = "all";
    }// w ww . jav  a  2 s  .  c  om
    Collection<String> databaseTypes = TestProperties.getDatabaseTypes(databaseType);
    ArrayList<Object[]> parameters = new ArrayList<Object[]>();
    for (String dbType : databaseTypes) {
        parameters.add(new Object[] { dbType, "latest" });
    }
    Object[][] array = new Object[parameters.size()][];
    parameters.toArray(array);
    return array;
}

From source file:Main.java

public static Object[] removeDuplicate(Object[] objs) {

    ArrayList<Object> objectArrayList = new ArrayList<Object>();
    if (objs == null || objs.length < 1) {
        return null;
    } else {//from w  w w  .  ja  va 2 s  . c  om
        for (int i = 0; i < objs.length; i++) {
            for (int j = objs.length; j > i; j--) {
                if (!objs[j].equals(objs[i])) {
                    objectArrayList.add(objs[j]);
                }
            }
        }

        Object[] objects = new Object[objectArrayList.size()];
        objects = objectArrayList.toArray(objects);
        return objects;
    }

}

From source file:com.opengamma.util.test.DbTest.java

protected static Object[][] getParametersForDatabase(final String databaseType) {
    ArrayList<Object[]> parameters = new ArrayList<Object[]>();
    for (String db : TestProperties.getDatabaseTypes(databaseType)) {
        parameters.add(new Object[] { db, "latest" });
    }//  w w w.  j  ava  2 s.  c  o  m
    Object[][] array = new Object[parameters.size()][];
    parameters.toArray(array);
    return array;
}

From source file:csv.FileManager.java

static public boolean appendItems(String fileName, ArrayList<ArrayList<String>> data,
        boolean firstRowIsHeader) {
    try {/*ww  w.j  a v a 2 s .co m*/
        BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
        CSVWriter writer = new CSVWriter(out);
        String[] t = new String[0];
        for (ArrayList<String> row : data) {
            if (!firstRowIsHeader) {
                boolean found = false;
                for (String str : row) {
                    if (!str.isEmpty()) {
                        found = true;
                    }
                }
                if (found)
                    writer.writeNext(row.toArray(t));
            } else
                firstRowIsHeader = false;
        }
        out.close();
        return true;
    } catch (Exception e) {
        System.out.println(e.getMessage());
        return false;
    }
}

From source file:mml.handler.get.MMLGetHandler.java

/**
 * Get an array of ALL the full version names in an MVD
 * @param mvd/*from  w ww .  j av  a 2 s .com*/
 * @return a list of full version names
 */
public static String[] getAllVersions(MVD mvd) {
    ArrayList<String> list = new ArrayList<String>();
    int numVersions = mvd.numVersions();
    for (short i = 1; i <= numVersions; i++) {
        String v = mvd.getVersionId(i);
        list.add(v);
    }
    String[] arr = new String[list.size()];
    list.toArray(arr);
    return arr;
}

From source file:fr.eurecom.nerd.core.proxy.ExtractivClient.java

private static PostMethod getExtractivProcessString(final URI extractivURI, final String content,
        final String serviceKey) throws FileNotFoundException {

    final PartBase filePart = new StringPart("content", content, null);

    // bytes to upload
    final ArrayList<Part> message = new ArrayList<Part>();
    message.add(filePart);//from   ww w  .  j  a  v a  2  s  .c om
    message.add(new StringPart("formids", "content"));
    message.add(new StringPart("output_format", "JSON"));
    message.add(new StringPart("api_key", serviceKey));

    final Part[] messageArray = message.toArray(new Part[0]);

    // Use a Post for the file upload
    final PostMethod postMethod = new PostMethod(extractivURI.toString());
    postMethod.setRequestEntity(new MultipartRequestEntity(messageArray, postMethod.getParams()));
    postMethod.addRequestHeader("Accept-Encoding", "gzip"); // Request the response be compressed (this is highly recommended)

    return postMethod;
}