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:Main.java

public static String[] trans(ArrayList<String> als) {
    String[] sa = new String[als.size()];
    als.toArray(sa);
    return sa;/*www  .ja  v  a2  s  .  com*/
}

From source file:Main.java

public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
    ArrayList<A> elements = new ArrayList<A>();
    while (enumeration.hasMoreElements())
        elements.add(enumeration.nextElement());
    return elements.toArray(array);
}

From source file:Main.java

public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
    ArrayList elements = new ArrayList();

    while (enumeration.hasMoreElements()) {
        elements.add(enumeration.nextElement());
    }/*from   w  w  w  .j a  v  a2 s  . c om*/

    return (A[]) elements.toArray(array);
}

From source file:Main.java

/**
 * Marshal the elements from the given enumeration into an array of the given type.
 * Enumeration elements must be assignable to the type of the given array. The array
 * returned will be a different instance than the array given.
 *///ww w. j  a v  a2  s . c o m
public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
    ArrayList<A> elements = new ArrayList<A>();
    while (enumeration.hasMoreElements()) {
        elements.add(enumeration.nextElement());
    }
    return elements.toArray(array);
}

From source file:Main.java

public static <T> T[] add(T[] current, T queueId) {
    ArrayList<T> asList = asList(current);
    asList.add(queueId);// www  . j av  a  2 s.c o  m
    T[] result = current.clone();
    return asList.toArray(result);
}

From source file:Main.java

public static <T> T[] remove(T[] current, T queueId) {
    ArrayList<T> asList = asList(current);
    asList.remove(queueId);//from   www  .  j a va 2 s. c o  m
    T[] result = current.clone();
    return asList.toArray(result);
}

From source file:Main.java

/**
 * Marshal the elements from the given enumeration into an array of the given type. Enumeration elements must be assignable to
 * the type of the given array. The array returned will be a different instance than the array given.
 *//*from  ww w .  j a v a 2  s .c o  m*/
public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
    ArrayList<A> elements = new ArrayList<>();
    while (enumeration.hasMoreElements()) {
        elements.add(enumeration.nextElement());
    }
    return elements.toArray(array);
}

From source file:Main.java

public static void setAllCapsInputFilter(EditText et) {
    InputFilter[] prefFilters;//from   w  w w .  java  2 s .  c o  m
    prefFilters = et.getFilters();
    ArrayList<InputFilter> filters = new ArrayList<>(Arrays.asList(prefFilters));
    filters.add(new InputFilter.AllCaps());
    prefFilters = new InputFilter[filters.size()];
    filters.toArray(prefFilters);
    et.setFilters(prefFilters);
}

From source file:Main.java

public static String[] join(String[] left, String[] right) {
    ArrayList<String> list = new ArrayList<String>();
    list.addAll(Arrays.asList(left));
    list.addAll(Arrays.asList(right));
    return (String[]) list.toArray(new String[list.size()]);
}

From source file:Main.java

/**
 * Uses a list of truth values to extract corresponding objects from an another array. Useful
 * assistant method for Wiki.exists(). If ol.length != bl.length, the method returns null.
 * Caveat: You will have to cast each item individally if you wish to treat it as anything other
 * than an Object./*from  w w w. j av  a  2s . c  om*/
 * 
 * @param ol The object list to use
 * @param bl The corresponding boolean list
 * @param searchvalue The values to look for in bl. Any value in bl matching searchvalue at a
 *           given index will cause the corresponding object in ol to be extracted and returned
 *           in the new array.
 * 
 * @return An Object array containing the corresponding values from bl.
 */
public static Object[] fetchCorresponding(Object[] ol, boolean[] bl, boolean searchvalue) {
    if (ol.length != bl.length)
        return null;

    ArrayList<Object> l = new ArrayList<Object>();
    for (int i = 0; i < ol.length; i++)
        if (bl[i] == searchvalue)
            l.add(ol[i]);

    return l.toArray(new Object[0]);
}