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

/**
 * Parses a whitespace separated series of name tokens.
 * @param stringValue the full string//  w  w w  .jav a  2s . co  m
 * @return an array of each constituent value, or null
 *  if there are no tokens (that is, the string is empty or
 *  all whitespace)
 */
static public String[] parseNameTokens(String stringValue) {
    List<String> list = parseNameTokensAsList(stringValue);

    if (list == null)
        return null;
    else
        return list.toArray(new String[list.size()]);

}

From source file:es.emergya.consultas.PatrullaConsultas.java

public static String[] getAllFilter() {
    List<String> res = new ArrayList<String>();
    res.add("");/* w  w  w  .  j  a  v a 2 s . c  om*/
    res.addAll(patrullaHome.getAllNames());
    return res.toArray(new String[0]);
}

From source file:io.amira.zen.json.JsonCast.java

public static String[] toArray(JSONArray jarr) throws JSONException {
    List<String> list = new ArrayList<String>();
    for (int i = 0; i < jarr.length(); i++) {
        list.add(jarr.getString(i));//  w w  w.  j  a v  a  2s  . c  om
    }
    String[] arr = new String[list.size()];
    arr = list.toArray(arr);
    return arr;
}

From source file:net.femtoparsec.jwhois.utils.ByteUtils.java

/**
 * Convert an array of bytes to an array of lines
 * @param data the given array of bytes// w ww.j av  a2s.co  m
 * @return an array of string
 */
public static String[] bytesToStrings(byte[] data) {
    if (data == null) {
        return null;
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
    LineIterator lineIterator = IOUtils.lineIterator(new InputStreamReader(inputStream));

    List<String> lines = new LinkedList<String>();
    while (lineIterator.hasNext()) {
        lines.add(lineIterator.nextLine());
    }

    return lines.toArray(new String[lines.size()]);
}

From source file:Main.java

/**
 * Join the {@code strings} into one string.
 * //  ww  w. jav a  2  s. c om
 * @param strings the string list to join
 * 
 * @return the joined string
 */
public static String join(List<String> strings) {
    if (strings == null) {
        throw new NullPointerException("argument 'strings' cannot be null");
    }
    return join(strings.toArray(new String[strings.size()]));
}

From source file:org.paxml.util.DBUtils.java

public static int[] runSqlResource(DataSource ds, String uri) {
    JdbcTemplate temp = new JdbcTemplate(ds);
    List<String> list = DBUtils.breakSql(PaxmlUtils.readResourceToString(uri, null));
    return temp.batchUpdate(list.toArray(new String[list.size()]));

}

From source file:bad.robot.http.apache.Coercions.java

public static Headers asHeaders(org.apache.http.Header[] headers) {
    List<Header> list = new ArrayList<Header>();
    for (org.apache.http.Header header : headers)
        list.add(header(header.getName(), header.getValue()));
    return headers(list.toArray(new Header[list.size()]));
}

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

private static void fillErrors(List<ErrorSection> errorSections, StatementContext context) {
    SQLException sqlException = null;
    if (errorSections != null) {
        for (ErrorSection section : errorSections) {
            sqlException = new SQLException(section.getMessage(), section.getState());
            List<StackTraceElement> list = getStackTrace(section);
            sqlException.setStackTrace(list.toArray(new StackTraceElement[list.size()]));
            context.addException(sqlException);
        }/* ww  w . j av a 2s  . co  m*/
    }
    if (sqlException != null) {
        throw new AtsdRuntimeException(sqlException.getMessage(), sqlException);
    }
}

From source file:com.kelveden.rastajax.cli.Runner.java

private static Set<FlatResource> loadRepresentation(List<URL> urls, String packages) {

    final ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[] {}),
            Runner.class.getClassLoader());

    final ClassLoaderRootResourceScanner scanner = new ClassLoaderRootResourceScanner(classLoader,
            packages.split(",")).allowInterfaceInheritance();

    return RestDescriber.describeApplication(scanner.scan(), new FlatRepresentationBuilder());
}

From source file:Main.java

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