Example usage for java.util ArrayList add

List of usage examples for java.util ArrayList add

Introduction

In this page you can find the example usage for java.util ArrayList add.

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:Main.java

public static ArrayList<Integer> shuffleArray(int size) {
    ArrayList<Integer> shuffled = new ArrayList<>();
    for (int i = 0; i < size; i++) {
        shuffled.add(i);
    }/* w  w w  .  j  a va 2  s  .c o  m*/

    Random rnd = new Random();
    for (int i = size - 1; i > 0; i--) {
        int index = rnd.nextInt(i + 1);
        // Simple swap
        int a = shuffled.get(index);
        shuffled.set(index, shuffled.get(i));
        shuffled.set(i, a);
    }

    return shuffled;
}

From source file:Main.java

public static <T> int addAll(final T[] source, final ArrayList<T> destination) {
    int count = 0;
    for (final T sourceItem : source) {
        destination.add(sourceItem);
        ++count;/*from   w  w w  . j a va  2 s  .  c  o  m*/
    }

    return count;
}

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 w w  w.  j a v a 2s. 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 <T> ArrayList<T> add(ArrayList<T> cur, T val) {
    if (cur == null) {
        cur = new ArrayList<T>();
    }/*from  www  .java 2 s  .c o m*/
    cur.add(val);
    return cur;
}

From source file:Main.java

public static <T> List<T> asList(final T t, final T... ts) {
    final ArrayList<T> list = new ArrayList<T>(ts.length + 1);
    list.add(t);
    Collections.addAll(list, ts);
    return list;/*from w  ww  .  j a  v  a 2s  .c  o  m*/
}

From source file:Main.java

public static ArrayList<Byte> getData(int dataLength) {
    ArrayList<Byte> data = new ArrayList<Byte>(dataLength);
    for (int i = 0; i < dataLength; i++)
        data.add((byte) i);
    return data;//from  w w w. j  av  a 2s . c  o  m
}

From source file:Main.java

public static List toMutableList(Object[] array) {
    final ArrayList result = new ArrayList(array.length);
    for (int i = 0; i < array.length; i++) {
        result.add(array[i]);
    }/*  ww  w.jav a 2s  . c o m*/
    return result;
}

From source file:Main.java

public static List<Double> parseDoubleJsonList(JSONArray array) throws JSONException {
    if (array == null) {
        return new ArrayList<Double>();
    }//from   www . j  a  v a  2 s  .c om

    int size = array.length();
    ArrayList<Double> list = new ArrayList<Double>(size);
    for (int i = 0; i < size; i++) {
        list.add(array.getDouble(i));
    }

    return list;
}

From source file:Main.java

public static int[] getAnimationsList() {
    ArrayList<Integer> animList = new ArrayList<Integer>();
    animList.add(ANIMATION_DEFAULT);
    animList.add(ANIMATION_FADE);/*from   w ww  .  ja  v  a2s  . c  om*/
    animList.add(ANIMATION_SLIDE_RIGHT);
    animList.add(ANIMATION_SLIDE_LEFT);
    animList.add(ANIMATION_SLIDE_RIGHT_NO_FADE);
    animList.add(ANIMATION_SLIDE_LEFT_NO_FADE);
    animList.add(ANIMATION_SLIDE_UP);
    animList.add(ANIMATION_SLIDE_DOWN);
    animList.add(ANIMATION_TRANSLUCENT);
    animList.add(ANIMATION_GROW_SHRINK);
    animList.add(ANIMATION_GROW_SHRINK_CENTER);
    animList.add(ANIMATION_GROW_SHRINK_BOTTOM);
    animList.add(ANIMATION_GROW_SHRINK_LEFT);
    animList.add(ANIMATION_GROW_SHRINK_RIGHT);
    int length = animList.size();
    int[] anim = new int[length];
    for (int i = 0; i < length; i++) {
        anim[i] = animList.get(i);
    }
    return anim;
}

From source file:net.reichholf.dreamdroid.intents.IntentFactory.java

public static Intent getStreamFileIntent(String fileName, String title) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    SimpleHttpClient shc = SimpleHttpClient.getInstance();
    ArrayList<NameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("file", fileName));
    Uri uri = Uri.parse(shc.buildFileStreamUrl(URIStore.FILE, params));
    Log.i(DreamDroid.LOG_TAG, "Streaming file: " + uri.getEncodedQuery());

    intent.setDataAndType(uri, "video/*");
    intent.putExtra("title", title);
    return intent;
}