Example usage for java.util ArrayList get

List of usage examples for java.util ArrayList get

Introduction

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

Prototype

public E get(int index) 

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:Main.java

static public double[] toDoubleArray(ArrayList list) {
    double[] result = new double[list.size()];

    for (int i = 0; i < list.size(); i++) {
        Number n = (Number) list.get(i);
        result[i] = n.doubleValue();/*from  w  ww .  j a  v a2s . c  om*/
    }

    return result;
}

From source file:Main.java

private static boolean isValidSubString(ArrayList<String> list, String token) {
    if (list != null) {
        for (int i = 0; i < list.size(); ++i) {
            if (!((String) list.get(i)).startsWith(token)) {
                return false;
            }//from  w  w w  .  jav  a 2s  .co  m
        }

        return true;
    } else {
        return false;
    }
}

From source file:Main.java

/**** Check if the value is exist in the list ****/
public static boolean isExistInList(ArrayList<String> list, String value) {
    if (list == null)
        return false;
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i).equals(value)) {
            return true;
        }// ww  w. j  a  v  a  2s. c  o  m
    }
    return false;
}

From source file:Main.java

public static long[] toArray(ArrayList<Long> src) {
    long[] res = new long[src.size()];
    for (int i = 0; i < src.size(); i++) {
        res[i] = src.get(i);
    }/*  w ww  .  ja  va  2  s.  c  o m*/
    return res;
}

From source file:Main.java

public static byte[] asByteList(ArrayList<Byte> list) {
    int size = list.size();
    byte[] byteList = new byte[size];
    for (int i = 0; i < size; i++) {
        byteList[i] = list.get(i);
    }// w ww  .  ja  v  a2  s .c  om
    return byteList;
}

From source file:Main.java

/**
 * Combine messages in an array and put a size header before each message
 * @param array/*w  w  w.j  a  va2 s.  c  o m*/
 * @return
 */
public static byte[] compileMessages(ArrayList<byte[]> array) {

    int bufferSize = 0;
    for (int i = 0; i < array.size(); i++) {
        byte[] thisByte = array.get(i);
        bufferSize += (4 + thisByte.length);
    }

    byte[] buffer = new byte[bufferSize];

    int pointer = 0; // used to index the next empty byte to fill
    for (int i = 0; i < array.size(); i++) {
        int thisSize = array.get(i).length;
        System.arraycopy(ByteBuffer.allocate(4).putInt(thisSize).array(), 0, buffer, pointer, 4);
        System.arraycopy(array.get(i), 0, buffer, pointer + 4, thisSize);
        pointer += (4 + thisSize);
    }

    return buffer;
}

From source file:Main.java

public static ArrayList<Double> matrixMinus(ArrayList<Double> a1, ArrayList<Double> a2) {
    ArrayList<Double> res = new ArrayList<Double>();
    for (int i = 0; i < a1.size(); i++) {
        res.add(a1.get(i) - a2.get(i));
    }/*from ww  w  .jav a  2s  .c  o  m*/
    return res;
}

From source file:Main.java

public static String[] intToString(ArrayList<Integer> list) {
    String string[] = new String[list.size()];
    for (int i = 0; i < string.length; i++) {
        string[i] = Integer.toString(list.get(i));
    }/*from  www . ja va  2s  .c  om*/
    return string;
}

From source file:Main.java

public static CharSequence[] toCharSequenceArray(ArrayList<String> strings) {
    CharSequence[] list = new CharSequence[strings.size()];
    for (int i = 0; i < strings.size(); ++i) {
        list[i] = strings.get(i);
    }/*  w w  w. j  a v a 2 s. c om*/
    return list;
}

From source file:Main.java

private static <T> boolean removeAllFromArrayList(ArrayList<T> collection, Collection<?> toRemove) {
    boolean result = false;
    for (int i = collection.size(); --i >= 0;)
        if (toRemove.contains(collection.get(i))) {
            collection.remove(i);//from  ww w .j a v a  2  s.c om
            result = true;
        }
    return result;
}