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 int indexOf(List<String> list, String target, int fromIndex) {
    for (int i = fromIndex + 1; i < list.size(); i++) {
        if (list.get(i).equalsIgnoreCase(target)) {
            return i;
        }//w w w  . j a v a  2  s.  c o  m
    }
    return -1;
}

From source file:Main.java

public static String xPathEvalSingle(String content, String expression) throws XPathExpressionException {
    List<String> result = xPathEvalList(content, expression);
    if (result.size() > 0)
        return result.get(0);
    else//from  w  ww  . j a  va  2 s .  c o  m
        return null;
}

From source file:Main.java

public static Element getElement(Element parent, String tagName) {
    List children = getElements(parent, tagName);
    return children.isEmpty() ? null : (Element) children.get(0);
}

From source file:Main.java

private static <T> T get(List<T> list, int index) {
    if (list.size() <= index) {
        return null;
    }/*  w  w  w.ja  v a2  s . c om*/
    return list.get(index);
}

From source file:Main.java

public static <T> T last(List<T> in) {
    if (in == null)
        return null;
    if (in.size() == 0)
        return null;
    return in.get(in.size() - 1);
}

From source file:Main.java

public static <T> T first(List<T> in) {
    if (in == null)
        return null;
    if (in.size() == 0)
        return null;
    return in.get(0);
}

From source file:Main.java

public static int[] toIntArray(final List<Integer> l) {
    final int[] r = new int[l.size()];
    for (int i = 0; i < l.size(); i++) {
        r[i] = l.get(i);
    }/*  w w  w.  j a  v  a2 s.  c o  m*/
    return r;
}

From source file:Main.java

public static int[] closetFramerate(Camera.Parameters parameters, float frameRate) {
    int framerate = (int) (frameRate * 1000);
    List<int[]> rates = parameters.getSupportedPreviewFpsRange();
    int[] bestFramerate = rates.get(0);
    for (int i = 0; i < rates.size(); i++) {
        int[] rate = rates.get(i);
        Log.e(TAG, "supported preview pfs min " + rate[0] + " max " + rate[1]);
        int curDelta = Math.abs(rate[1] - framerate);
        int bestDelta = Math.abs(bestFramerate[1] - framerate);
        if (curDelta < bestDelta) {
            bestFramerate = rate;// w  w  w.j ava 2 s.  com
        } else if (curDelta == bestDelta) {
            bestFramerate = bestFramerate[0] < rate[0] ? rate : bestFramerate;
        }
    }
    return bestFramerate;
}

From source file:Main.java

public static int checkModel_1(List<String> list, String[] s) {
    for (int j = 0, len2 = list.size(); j < len2; j++) {
        String ss[] = list.get(j).split(",");
        for (int k = 0; k < ss.length; k++) {
            for (int m = 0; m < s.length; m++) {
                if (s[m].equals(ss[k])) {
                    return 1;
                }//from w  ww  .  ja v  a2 s  .  c  o m
            }
        }
    }
    return 0;
}

From source file:Main.java

/**
 * Determines whether a given collection contains duplicate
 * values./* www. ja  v  a  2 s .c  o  m*/
 *
 * @return true iff the given collection contains duplicate
 *       values.
 * @param   <T>   The type of the collection elements.
 * @param   elements   A collection.
 */
public static <T> boolean hasDuplicates(final List<T> elements) {
    for (int i = 0; i < elements.size() - 1; i++) {
        final T element = elements.get(i);
        for (int j = i + 1; j < elements.size(); j++) {
            if (elements.get(j).equals(element))
                return true;
        }
    }
    return false;
}