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:com.edgenius.wiki.service.impl.BackupServiceImpl.java

public static void main(String[] args) throws FileUtilException, IOException {
    //TODO: this part code may move to UnitTest in future
    List<Page> container = new ArrayList<Page>();
    List<Page> parents = new ArrayList<Page>();

    Page a = new Page();
    a.setPageUuid("a");
    Page b = new Page();
    b.setPageUuid("b");
    Page c = new Page();
    c.setPageUuid("c");
    Page d = new Page();
    d.setPageUuid("d");

    d.setParent(c);//from  w  w w.java 2s .c  om
    c.setParent(b);
    b.setParent(a);
    //      a.setParent(d);

    BackupServiceImpl im = new BackupServiceImpl();
    im.processParentPage(container, d, parents, new ContentBodyMap());

    System.out.println(Arrays.toString(container.toArray()));
}

From source file:Main.java

public static <T> T[] toArray(List<T> list) {
    return (T[]) list.toArray();
}

From source file:Main.java

/**
 * Parses the list to the array./* w  w  w.  j a  va 2s  .c  o m*/
 * @param list the instance of List 
 * @return the array 
 */
public static Object[] parseArray(List list) {
    return list.toArray();
}

From source file:Main.java

/**
 * Convert List to array//from   ww  w .j ava2  s  .com
 * 
 * Example:
 *     String[] myarray = (String[]) ArrayUtil.list2Array(mylist);
 * 
 * @param list
 * @return
 */
public static <T> Object[] list2Array(List<T> list) {
    return list.toArray();
}

From source file:Main.java

public static <T> String mkString(String separator, List<T> ss) {
    return mkString(separator, ss.toArray());
}

From source file:Main.java

public static List<Integer> sort(List<Integer> srcList) {
    Object[] ary = srcList.toArray();
    java.util.Arrays.sort(ary);/* w w  w  .  j  a v a 2  s .  c  o  m*/

    List<Integer> resultList = new ArrayList<Integer>();
    for (Object val : ary) {
        resultList.add(Integer.parseInt(val.toString()));
    }

    return resultList;
}

From source file:io.github.rhkiswani.javaff.lang.utils.ArraysUtils.java

public static boolean isEmpty(List list) {
    return isEmpty(list.toArray());
}

From source file:Main.java

public static Object[] toArray(List list) {
    return list.toArray();
}

From source file:Main.java

public static Object toArray(List<?> list, Class<?> componentType) {
    Object result = Array.newInstance(componentType, list.size());
    System.arraycopy(list.toArray(), 0, result, 0, list.size());
    return result;
}

From source file:com.pivotal.cf.mobile.ats.json.JsonFunctions.java

public static Object convert(Object o) {
    if (o instanceof Collection<?>) {
        List<?> original = (List<?>) o;
        Object[] array = original.toArray();
        for (int i = 0; i < array.length; i++) {
            array[i] = convert(array[i]);
        }/*from   ww w .j av  a2s .  co m*/
        return jdk.nashorn.internal.objects.Global.allocate(array);
    } else if (o instanceof Map<?, ?>) {
        jdk.nashorn.internal.scripts.JO jo = new jdk.nashorn.internal.scripts.JO(
                jdk.nashorn.internal.runtime.PropertyMap.newMap());
        ((Map<?, ?>) o).forEach((k, v) -> jo.put(k, convert(v), false));
        return jo;
    } else {
        return o;
    }
}