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 final String getTopAppPackageName(final Context context) {
    String packageName = null;// ww w .j av  a  2 s.  co  m
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    List<RunningTaskInfo> list = am.getRunningTasks(1);
    ComponentName comp = list.get(0).topActivity;
    if (null != comp) {
        packageName = comp.getPackageName();
    }
    return packageName;
}

From source file:Main.java

public static <T> int getObjectIndex(T obj, List<T> set) {

    for (int i = 0; i < set.size(); i++) {
        T element = set.get(i);
        if (element.equals(obj)) {
            return i;
        }// w  ww  . j ava2s .c  om
    }

    return -1;
}

From source file:Main.java

public static boolean isSingleActivity(Context ctx) {
    ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1);
    return tasks.get(0).numRunning == 1;
}

From source file:Main.java

public static <T> T getFirst(List<T> l) {
    if (l == null || l.isEmpty())
        return null;
    return l.get(0);
}

From source file:Main.java

/**
 * Returns the index of the given value in the given list,
 * using == to compare rather than .equals.
 *///from w  w  w  .ja  va  2 s  .c o  m
public static <T> int indexOfSafe(List<T> list, T value) {
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i) == value) {
            return i;
        }
    }
    return -1;
}

From source file:Main.java

public static <T> List<List<T>> matrixTransform(List<List<T>> datas) {
    if (datas.size() == 0 || datas.get(0).size() == 0) {
        return datas;
    }// ww  w  .ja v  a 2  s  .co m
    int column = datas.size();
    int row = datas.get(0).size();
    List<List<T>> newData = new ArrayList<>(row);
    for (int i = 0; i < row; i++) {
        List<T> list = new ArrayList<>(column);
        for (int j = 0; j < column; j++) {
            list.add(datas.get(j).get(i));
        }
        newData.add(list);
    }
    return newData;
}

From source file:Main.java

public static <T> T last(List<T> list) {
    if (list.isEmpty()) {
        return null;
    }//from  w ww.  ja v a  2 s  .  co  m
    return list.get(list.size() - 1);
}

From source file:Main.java

public static <T> T getSingleResult(List<T> results) {
    return (results == null || results.isEmpty()) ? null : results.get(0);
}

From source file:Main.java

public static <T> T atOrNull(List<T> list, int index) {
    if (list.size() <= index)
        return null;
    return list.get(index);
}

From source file:Main.java

public static List<HashMap<String, String>> addCheckboxSupport(List<HashMap<String, String>> list) {
    for (int i = 0; i < list.size(); i++) {
        list.get(i).put("isChecked", "false");
    }/*from   ww  w.j av  a  2s  .  c  o  m*/
    return list;
}