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 MBeanServer findMBeanServer() {
    ArrayList<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
    if (servers == null || servers.isEmpty()) {
        return ManagementFactory.getPlatformMBeanServer();
    }//ww  w .j a v  a 2s .c  o m

    return servers.get(0);
}

From source file:Main.java

public static String convertListToStringForQuery(ArrayList<Integer> list) {
    String result = "(";
    for (int i = 0; i < list.size(); i++) {
        if (i != 0) {
            result = result + ",";
        }/*from w  w w. j  a  v  a2  s  . c o  m*/
        result = result + list.get(i).toString();
    }
    result = result + ")";
    return result;
}

From source file:Main.java

public static String getCommaSeperatedString(ArrayList<String> stringArrayList) {
    StringBuilder stringBuilder = new StringBuilder();
    String sep = ", ";
    for (int i = 0; i < stringArrayList.size(); i++) {
        stringBuilder.append(stringArrayList.get(i));
        if (i != stringArrayList.size() - 1) {
            stringBuilder.append(sep);// w ww  .  jav a  2 s.c om
        }
    }
    return stringBuilder.toString();
}

From source file:Main.java

public static String arrayListToString(ArrayList<String> stringList, String split) {
    StringBuilder builder = new StringBuilder();
    if (null != stringList) {
        for (int i = 0; i < stringList.size(); i++) {
            builder.append(stringList.get(i).trim());
            if (i < stringList.size() - 1) {
                builder.append(split);/*from  ww w. j  a v a 2 s .c om*/
            }
        }
    }
    return builder.toString();
}

From source file:MonteCarloWindowLogic.java

static private void divideOnPairsAndConvertConvexHullIntoSeries(XYSeries[] seriesDestination,
        ArrayList<Point2D> convexHull) {
    for (int i = 1; i < convexHull.size(); i++) {
        seriesDestination[i - 1].add(convexHull.get(i - 1).getX(), convexHull.get(i - 1).getY());
        seriesDestination[i - 1].add(convexHull.get(i).getX(), convexHull.get(i).getY());
    }/*from  w  w w .  j a va 2 s.  c o  m*/
}

From source file:Main.java

public static String gettype(HashMap<String, Object> info) {
    if (info != null) {
        ArrayList replies_tree = (ArrayList) info.get("replies_tree");
        if (replies_tree != null && replies_tree.size() > 0) {
            HashMap<String, Object> answers = (HashMap<String, Object>) replies_tree.get(0);
            if (answers != null) {
                ArrayList classes = (ArrayList) answers.get("answer");
                if (classes != null) {
                    HashMap<String, Object> class1 = (HashMap<String, Object>) classes.get(0);
                    if (class1 != null) {
                        return class1.get("type").toString();
                    }//from   ww  w .j a  va2s .c  o m
                }

            }

        }

    }

    return null;
}

From source file:Main.java

/**
 * Method to join array elements of type string
 * //from w w  w  . j  a v  a2s  . co m
 * @param input
 *            Array which contains strings
 * @param glue
 *            String between each array element
 * @return String containing all array elements separated by glue string
 */
public static String implode(ArrayList<String> list, String glue) {
    String[] input = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
        input[i] = list.get(i);
    }
    return implode(input, glue);
}

From source file:Main.java

public static byte[] toBytes(ArrayList<Byte> data) {
    byte[] rval = new byte[data.size()];
    for (int i = 0; i < data.size(); i++) {
        rval[i] = data.get(i);
    }/*from   ww w .  ja v a  2s . co m*/
    return rval;
}

From source file:Main.java

/**
 * Return the first N items in a collection.
 *
 *//*from w  w  w.ja  v a  2 s.  c  o m*/
public static <T> List<T> head(Collection<T> input, int count) {

    List<T> result = Lists.newArrayList();

    ArrayList<T> tmp = Lists.newArrayList();
    tmp.addAll(input);

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

        if (result.size() == count)
            break;

        result.add(tmp.get(i));

    }

    return result;

}

From source file:Main.java

public static String arrayParamToString(ArrayList<String> strings) {

    String arrayToStringParam = "";

    if (strings != null && !strings.isEmpty()) {

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

            String param = strings.get(i);

            if (i == 0)
                arrayToStringParam += param;
            else//  w w w . ja v a  2  s  . com
                arrayToStringParam += "," + param;

        }
    }

    return arrayToStringParam;
}