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

public static boolean isScalar(ArrayList<?> shape) {
    if (shape != null) {
        for (int i = 0; i < shape.size(); i++) {
            if (null == shape.get(i) || !("1").equals(shape.get(i).toString())) {
                return false;

            }/* w  w w . j  a v a  2 s  .c  o m*/
        }
    }
    return true;
}

From source file:Main.java

public static int indexOf(Object o, ArrayList<Object> elementData) {
    if (o == null) {
        for (int i = 0; i < elementData.size(); i++)
            if (elementData.get(i) == null)
                return i;
    } else {/*from  w  w w  .j  a  v a 2  s . c  o m*/
        for (int i = 0; i < elementData.size(); i++)
            if (o.equals(elementData.get(i)))
                return i;
    }
    return -1;
}

From source file:Main.java

/**
 * create new Array and copy from {@code src} to it. no effect to
 * {@code src}.//from w ww.  j av  a2s . c  om
 */
static public long[] new_array_from(ArrayList<Long> src) {
    final long[] dest = new long[src.size()];
    for (int i = 0; i < src.size(); ++i) {
        dest[i] = src.get(i).longValue();
    }
    return dest;
}

From source file:Main.java

public static Date get(List<Date> otherDates, Date dateToApproach) {
    final TreeSet<Date> set = new TreeSet<Date>(otherDates);
    set.add(dateToApproach);/*w  ww  . ja  v a2 s. c o m*/
    final ArrayList<Date> list = new ArrayList<Date>(set);
    final int indexOf = list.indexOf(dateToApproach);
    if (indexOf == 0)
        return null;
    return list.get(indexOf - 1);
}

From source file:Main.java

private static int[] toIntArray(ArrayList<Integer> arrayList) {
    int[] ret = new int[arrayList.size()];
    for (int i = 0; i < ret.length; i++) {
        ret[i] = arrayList.get(i);
    }/*www .j a v a  2 s  . c  o m*/
    return ret;
}

From source file:Main.java

public static String[] toStringArray(ArrayList<String> array) {
    String arr[] = new String[array.size()];

    for (int i = 0; i < array.size(); i++) {
        arr[i] = array.get(i);
    }//  w ww .j  a  v  a  2 s.  co  m

    return arr;
}

From source file:Main.java

public static String getCommaSeparatedStringFromArray(ArrayList list) {
    StringBuilder result = new StringBuilder();

    for (int i = 0; i < list.size(); i++) {
        result.append(list.get(i));
        result.append(",");
    }/*from   ww  w.jav a2  s .co  m*/

    return result.length() > 0 ? result.substring(0, result.length() - 1) : "";
}

From source file:Main.java

public static Object[] toObjectArray(ArrayList<Object> array) {
    Object arr[] = new Object[array.size()];

    for (int i = 0; i < array.size(); i++) {
        arr[i] = array.get(i);
    }//from  w w  w  . j av  a2s . c  o  m

    return arr;
}

From source file:Main.java

/**
 * transforms an ArrayList of Double values to an Array of double values
 * @param _list the ArrayList with Double values
 * @return an array with double values/*  w  w  w .  ja v a 2 s.  c om*/
 */
public static double[] getDoubleArrayFromArrayList(ArrayList<Double> _list) {
    double[] res = new double[_list.size()];
    for (int i = 0; i < res.length; i++) {
        res[i] = _list.get(i).doubleValue();
    }
    return res;
}

From source file:Main.java

public static double computeDistance(ArrayList<Double> d1, ArrayList<Double> d2) {
    double squareSum = 0;
    for (int i = 0; i < d1.size() - 1; i++) {
        squareSum += (d1.get(i) - d2.get(i)) * (d1.get(i) - d2.get(i));
    }/*from  w  w  w . j  av  a2 s  .  c  o  m*/
    return Math.sqrt(squareSum);
}