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:gov.nih.nci.caintegrator.application.util.CSVUtil.java

public static void renderCSV(HttpServletResponse response, List<List> csv) {
    PrintWriter out = null;//from  w w w. j  a v a 2 s.  c  o  m

    long randomness = System.currentTimeMillis();
    response.setContentType("application/csv");
    response.setHeader("Content-Disposition", "attachment; filename=report_" + randomness + ".csv");

    try {
        for (List row : csv) {

            out = response.getWriter();
            out.write(StringUtils.join(row.toArray(), ",") + "\r\n");
            out.flush();
        }
    } catch (Exception e) {
        out.write("error generating report");
    }
}

From source file:Main.java

/**
 * Converts a list to a new copy of array based on the start index and end index.
 * //  ww w.  jav  a 2 s. co m
 * @param list
 * @param startIndex
 * @param endIndex
 * @return
 */
@SuppressWarnings({ "unchecked", "cast" })
public static final <T> T[] toArray(List<T> list, int startIndex, int endIndex) {
    if (isEmpty(list)) {
        return (T[]) list.toArray();
    }
    List<T> subList = list.subList(startIndex, endIndex);
    return (T[]) subList
            .toArray((T[]) java.lang.reflect.Array.newInstance(list.get(0).getClass(), subList.size()));
}

From source file:io.druid.client.cache.CacheDistributionTest.java

@Parameterized.Parameters(name = "repetitions={0}, hash={1}")
public static Iterable<Object[]> data() {
    List<HashAlgorithm> hash = ImmutableList.of(DefaultHashAlgorithm.FNV1A_64_HASH,
            DefaultHashAlgorithm.KETAMA_HASH, MemcachedCache.MURMUR3_128);
    List<Integer> repetitions = Arrays.asList(160, 500, 1000, 2500, 5000);

    Set<List<Object>> values = Sets.cartesianProduct(Sets.newLinkedHashSet(hash),
            Sets.newLinkedHashSet(repetitions));
    return Iterables.transform(values, new Function<List<Object>, Object[]>() {
        @Nullable//from   w ww .  j a va  2  s.  c  o m
        @Override
        public Object[] apply(List<Object> input) {
            return input.toArray();
        }
    });
}

From source file:de.dfki.resc28.ole.bootstrap.Util.java

public static Literal toStringLiteral(List<TerminalNode> tokens, String separator) {
    return ResourceFactory.createTypedLiteral(StringUtils.join(tokens.toArray(), separator),
            XSDDatatype.XSDstring);/*w w  w .j  a  v a 2 s. co m*/
}

From source file:de.dfki.resc28.ole.bootstrap.Util.java

public static Literal toURLEncodedStringLiteral(List<TerminalNode> tokens, String separator) {
    return ResourceFactory.createTypedLiteral(Util.urlEncoded(StringUtils.join(tokens.toArray(), separator)),
            XSDDatatype.XSDstring);//from   w  w  w.ja v  a2 s. co m
}

From source file:com.fengduo.bee.commons.core.lang.ArrayUtils.java

@SuppressWarnings("unchecked")
public static <E extends Object> E[] listConvert(List<E> list) {
    return Argument.isEmpty(list) ? null : (E[]) list.toArray();
}

From source file:Main.java

public static <T> boolean isListIdentical(List<T> listA, List<T> listB) {
    if (listA == null || listB == null) {
        throw new IllegalArgumentException("input list should not be null");
    }/*from  www .java  2  s . c  o m*/

    Object[] arrayA = listA.toArray();
    Object[] arrayB = listB.toArray();

    boolean ret = Arrays.equals(arrayA, arrayB);

    return ret;
}

From source file:it.attocchi.utils.StringFunc.java

public static String writeLines(List<String> lines, String defaultValueIfEmpty) {
    String res = defaultValueIfEmpty;

    if (ListUtils.isNotEmpty(lines))
        res = StringUtils.join(lines.toArray(), NEW_LINE);

    return res;/* w ww  .  j  a  v a  2 s .c om*/
}

From source file:com.groupon.odo.proxylib.Utils.java

public static HashMap<String, Object> getJQGridJSON(List<?> rows, String rowName) {
    return getJQGridJSON(rows.toArray(), rowName);
}

From source file:com.asual.summer.core.util.StringUtils.java

public static String join(List<String> list, String str) {
    return org.apache.commons.lang.StringUtils.join(list.toArray(), str);
}