Example usage for java.util List get

List of usage examples for java.util List get

Introduction

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

Prototype

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 getDistanceString(List<String> list) {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("&origin=").append(list.get(0));
    stringBuilder.append("&destination=").append(list.get(list.size() - 1));
    stringBuilder.append("&waypoints=");
    for (int i = 1; i < list.size() - 1; i++) {
        stringBuilder.append(list.get(i));
        if (i != list.size() - 2)
            stringBuilder.append("|");
    }/*w w  w .  ja v a 2 s . c o m*/
    return stringBuilder.toString();
}

From source file:Main.java

/**
 * Return the last item of the {@code List}. Null is returned if the list is null or empty.
 *
 * @param <T> Type of the items in the list
 * @param list Input list/*from  w w w. j  av  a2  s  .c o m*/
 * @return Last item of the list or null if the list is empty
 */
public static <T> T getLast(List<T> list) {
    if (list == null || list.isEmpty()) {
        return null;
    }

    return list.get(list.size() - 1);
}

From source file:Main.java

public static boolean isBackgroundRunning(Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = am.getRunningTasks(1);
    if (!tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        if (!topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }//from  w  w  w.  j  a va  2 s .co  m
    }
    return false;
}

From source file:Main.java

public static int[] copyListToArray(List<Integer> list) {
    int[] array = new int[list.size()];
    for (int t = 0; t < list.size(); t++) {
        array[t] = list.get(t);
    }/*  w  w  w.  java  2  s . c  om*/
    return array;
}

From source file:Main.java

public static boolean isApplicationBroughtToBackground(final Context context) {
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> tasks = am.getRunningTasks(1);
    if (!tasks.isEmpty()) {
        ComponentName topActivity = tasks.get(0).topActivity;
        if (!topActivity.getPackageName().equals(context.getPackageName())) {
            return true;
        }//  ww w.  j a  va  2s. co m
    }
    return false;
}

From source file:Main.java

public static long[] toPrimitiveLong(List<Long> list) {
    long[] array = new long[list.size()];
    for (int i = 0; i < list.size(); i++) {
        array[i] = list.get(i);
    }/*from www . j  a v  a  2 s.  c  om*/
    return array;
}

From source file:Main.java

public static <T extends Serializable> Bundle putArguments(Bundle bundle, String key, List<T> objects) {
    for (int i = 0; i < objects.size(); i++) {
        bundle.putSerializable(String.format("%s%s", key, i), objects.get(i));
    }//w  w  w .  j  a v a  2s. c  om
    return bundle;
}

From source file:Main.java

public static <T> T head(List<T> list) {
    if (list.size() == 0) {
        throw new IllegalStateException("head of empty list");
    }//from w ww .j  av  a  2 s .  c  o m
    return list.get(0);
}

From source file:Main.java

public static int getRIndex(List<Float> list) {
    float max = 0;
    int RIndex = 0;
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i) > max) {
            max = list.get(i);/*from  w  ww  . j  a va 2s .co  m*/
            RIndex = i;
        }
    }
    return RIndex;
}

From source file:Main.java

public static Node getSingleNode(Node node, String path) {
    List nodeList = getNodes(node, path);

    if (nodeList.size() > 0) {
        return (Node) nodeList.get(0);
    }/* w w w.j av a2 s.co m*/
    return null;
}