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 String[] stringListToArray(ArrayList<String> list) {
    String string[] = new String[list.size()];
    for (int i = 0; i < string.length; i++) {
        string[i] = list.get(i);
    }//from   ww  w .  j  a  v a 2 s.c  om
    return string;
}

From source file:Main.java

public static String getArrayListInString(ArrayList<Integer> array) {
    String numbers = "";

    for (int i = 0; i < array.size(); i++) {

        numbers = numbers + array.get(i);

        if (i != array.size() - 1) {
            numbers = numbers + ", ";
        }/*  w  w w .  ja v  a2s . c  om*/

    }
    return numbers;
}

From source file:Main.java

private static String[] toStringArray(ArrayList<String> arrayList) {
    String[] ret = new String[arrayList.size()];
    for (int i = 0; i < ret.length; i++) {
        ret[i] = arrayList.get(i);
    }// w w  w. ja  v a  2 s.  co  m
    return ret;
}

From source file:Main.java

public static void permute(Random random, ArrayList array) {
    for (int i = 0; i < array.size(); i++) {
        int j = i + random.nextInt(array.size() - i);
        Object tmp = array.get(i);
        array.set(i, array.get(j));//  w ww . j av a2s. c o m
        array.set(j, tmp);
    }
}

From source file:Main.java

private static String getCommonSubStringFromList(ArrayList<String> list) {
    if (list != null && list.size() > 0) {
        String[] tokens = ((String) list.get(0)).split("/");
        String path = null;/*from w w w  .ja  va 2  s.co  m*/
        String temp = "";

        for (int i = 0; i < tokens.length; ++i) {
            if (!tokens[i].trim().isEmpty()) {
                temp = temp + "/" + tokens[i];
                if (isValidSubString(list, temp)) {
                    path = temp;
                }
            }
        }

        return path;
    } else {
        return null;
    }
}

From source file:Main.java

/**
 * //from   ww  w  .j  a  v a2  s  .c om
 * @param s
 * @param delimeter
 * @param fieldsToBeKept: idxes of the fields to be kept
 * @return
 */
public static ArrayList<Double> stringToDoubleList(String s, String delimeter, int[] fieldsToBeKept) {
    ArrayList<Double> ret = new ArrayList<Double>();
    ArrayList<Double> allFields = new ArrayList<Double>();
    for (int i = 0; i < fieldsToBeKept.length; i++) {
        ret.add(allFields.get(fieldsToBeKept[i]));
    }
    return ret;
}

From source file:Main.java

public static <T> int getFreq(ArrayList<ArrayList<T>> a, ArrayList<T> b) {
    int res = 0;//from   w  w w.  j av a2 s .co m
    for (int i = 0; i < a.size(); i++) {
        if (isContain(a.get(i), b)) {
            res++;
        }
    }
    return res;
}

From source file:Main.java

public static double getMindouble(ArrayList<Double> arr) {
    double min = Double.MAX_VALUE;

    for (int i = 0; i < arr.size(); i++) {
        double d = arr.get(i);
        if (d < min)
            min = d;//  w w  w  .  java 2 s .c om
    }

    return min;
}

From source file:Interface.Camembert.java

public static JPanel cCamembert(JFrame f, ArrayList<ArrayList> liste) {
    // On rcupre les 2 listes
    ArrayList<Integer> nb = liste.get(1);
    ArrayList<String> nom = liste.get(2);

    DefaultPieDataset pieDataset = new DefaultPieDataset();
    for (int i = 0; i < nb.size(); i++) {
        pieDataset.setValue(nom.get(i) + " : " + nb.get(i), nb.get(i));
    }//from  w  w w  .ja va 2  s  .co  m

    JFreeChart pieChart = ChartFactory.createPieChart("Nombre d'interventions par mdecin", pieDataset, true,
            true, true);

    ChartPanel cPanel = new ChartPanel(pieChart);

    return cPanel;
}

From source file:Main.java

public static <E> void removeDuplicate(ArrayList<E> list) {
    for (int i = 0; i < list.size() - 1; i++) {
        for (int j = list.size() - 1; j > i; j--) {
            if (list.get(j).equals(list.get(i))) {
                list.remove(j);/*from w w  w.ja  v a2s.  com*/
            }
        }
    }
}