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

/**
 * Filters the inputs, maps them given the mapping function and adds them in the array provided
 * by the generator.//from  ww w.j a  v a2 s .c om
 */
public static <T, R> R[] filterAndMapToArray(T[] inputs, Predicate<? super T> predicate,
        Function<? super T, ? extends R> mapper, IntFunction<R[]> arrayGenerator) {
    List<R> resultList = new ArrayList<>();
    for (T t : inputs) {
        if (predicate.test(t)) {
            resultList.add(mapper.apply(t));
        }
    }
    return resultList.toArray(arrayGenerator.apply(resultList.size()));
}

From source file:com.taobao.datax.engine.schedule.JarLoader.java

private static URL[] getUrls(String[] paths) {
    if (null == paths || 0 == paths.length) {
        throw new IllegalArgumentException("Paths cannot be empty .");
    }/*from   w  ww.j  ava  2s  .  c  o  m*/

    List<URL> urls = new ArrayList<URL>();
    for (String path : paths) {
        urls.addAll(Arrays.asList(getUrl(path)));
    }

    return urls.toArray(new URL[0]);
}

From source file:com.mingo.parser.xml.dom.DocumentBuilderFactoryCreator.java

/**
 * Creates schema from list of {@link Source} objects.
 *
 * @param sources list of {@link Source}
 * @return immutable in-memory representation of grammar
 * @throws ParserConfigurationException {@link ParserConfigurationException}
 *///  w ww . ja  v a 2  s. c o m
private static Schema createSchema(List<Source> sources) throws ParserConfigurationException {
    Schema schema;
    try {
        schema = SCHEMA_FACTORY.newSchema(sources.toArray(new Source[0]));
    } catch (SAXException e) {
        throw new ParserConfigurationException(ExceptionUtils.getMessage(e));
    }
    return schema;
}

From source file:com.google.dart.tools.ui.internal.refactoring.ServerRefactoring.java

public static String[] toStringArray(List<String> list) {
    return list.toArray(new String[list.size()]);
}

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

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

From source file:Main.java

public static File[] getXMLFiles(File folder) {
    List<File> aList = new ArrayList<File>();

    File[] files = folder.listFiles();
    for (File pf : files) {

        if (pf.isFile() && getFileExtensionName(pf).indexOf("xml") != -1) {
            aList.add(pf);// www. ja  va 2 s  . co m
        }
    }
    return aList.toArray(new File[aList.size()]);
}

From source file:Main.java

public static Object[] toArrayOnListOfSameType(List aList) {
    if (aList.isEmpty())
        return new Object[0];

    Class type = aList.get(0).getClass();
    Object[] sameElementsArray = (Object[]) Array.newInstance(type, aList.size());
    return aList.toArray(sameElementsArray);
}

From source file:com.github.jobs.api.GithubJobsApi.java

private static String createUrl(String url, List<NameValuePair> pairs) throws URIException {
    HttpMethod method = new GetMethod(url);
    NameValuePair[] nameValuePairs = pairs.toArray(new NameValuePair[pairs.size()]);
    method.setQueryString(nameValuePairs);
    return method.getURI().getEscapedURI();
}

From source file:dumpsection.util.Util.java

public static String[] stringArrayCharSetDefaultToDesired(String[] src, Charset charset)
        throws UnsupportedEncodingException {
    Charset cs = Charset.defaultCharset();
    List<String> strs = Arrays.asList(src);
    List<String> strd = new ArrayList<>();
    for (String str : strs) {
        strd.add(StringUtils.toEncodedString(str.getBytes(cs), Charset.forName("UTF-8")));
    }/*  w  ww.j a  v a  2  s  .  c  o  m*/
    return strd.toArray(src);
}

From source file:it.geosolutions.geobatch.destination.vulnerability.TargetPropertiesLoader.java

public static DistancesPair createPairDistance(List<Double> distances) {

    Double[] distancesInt = distances.toArray(new Double[distances.size()]);
    String[] distancesNames = new String[distancesInt.length];
    for (int j = 0; j < distancesInt.length; j++) {
        distancesNames[j] = "distance" + j;
    }//www  .  ja v a  2  s.  c  o  m
    return new DistancesPair(distancesNames, distancesInt);
}