java.util.ArrayList#lastIndexOf ( )源码实例Demo

下面列出了java.util.ArrayList#lastIndexOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: FocusFinder.java
private static View getNextFocusable(View focused, ArrayList<View> focusables, int count) {
    if (focused != null) {
        int position = focusables.lastIndexOf(focused);
        if (position >= 0 && position + 1 < count) {
            return focusables.get(position + 1);
        }
    }
    if (!focusables.isEmpty()) {
        return focusables.get(0);
    }
    return null;
}
 
public static void main(String[] args) {

    //create an ArrayList object
    ArrayList arrayList = new ArrayList();

    //Add elements to Arraylist
    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");
    arrayList.add("4");
    arrayList.add("5");
    arrayList.add("1");
    arrayList.add("2");

    /*
      To check whether the specified element exists in Java ArrayList use
      boolean contains(Object element) method.
      It returns true if the ArrayList contains the specified objct, false
      otherwise.
    */

    boolean blnFound = arrayList.contains("2");
    System.out.println("Does arrayList contain 2 ? " + blnFound);

    /*
      To get an index of specified element in ArrayList use
      int indexOf(Object element) method.
      This method returns the index of the specified element in ArrayList.
      It returns -1 if not found.
    */

    int index = arrayList.indexOf("4");
    if (index == -1) System.out.println("ArrayList does not contain 4");
    else System.out.println("ArrayList contains 4 at index :" + index);

    /*
      To get last index of specified element in ArrayList use
      int lastIndexOf(Object element) method.
      This method returns index of the last occurrence of the
      specified element in ArrayList. It returns -1 if not found.
    */

    int lastIndex = arrayList.lastIndexOf("1");
    if (lastIndex == -1) System.out.println("ArrayList does not contain 1");
    else System.out.println("Last occurrence of 1 in ArrayList is at index :" + lastIndex);
  }
 
public static void main(String[] args) {

        //create an ArrayList object
        ArrayList arrayList = new ArrayList();

        //Add elements to Arraylist
        arrayList.add("1");
        arrayList.add("2");
        arrayList.add("3");
        arrayList.add("4");
        arrayList.add("5");
        arrayList.add("1");
        arrayList.add("2");

    /*
      To check whether the specified element exists in Java ArrayList use
      boolean contains(Object element) method.
      It returns true if the ArrayList contains the specified objct, false
      otherwise.
    */

        boolean blnFound = arrayList.contains("2");
        System.out.println("Does arrayList contain 2 ? " + blnFound);

    /*
      To get an index of specified element in ArrayList use
      int indexOf(Object element) method.
      This method returns the index of the specified element in ArrayList.
      It returns -1 if not found.
    */

        int index = arrayList.indexOf("4");
        if (index == -1) System.out.println("ArrayList does not contain 4");
        else System.out.println("ArrayList contains 4 at index :" + index);

    /*
      To get last index of specified element in ArrayList use
      int lastIndexOf(Object element) method.
      This method returns index of the last occurrence of the
      specified element in ArrayList. It returns -1 if not found.
    */

        int lastIndex = arrayList.lastIndexOf("1");
        if (lastIndex == -1) System.out.println("ArrayList does not contain 1");
        else System.out.println("Last occurrence of 1 in ArrayList is at index :" + lastIndex);
    }
 
源代码4 项目: spotbugs   文件: ListTests.java
public void test3NoBugs(ArrayList<? extends CharSequence> list) {
    list.lastIndexOf(new StringBuffer("Key"));
}
 
源代码5 项目: spotbugs   文件: ListTests.java
public void test3Bugs(ArrayList<? extends CharSequence> list) {
    list.lastIndexOf(Integer.valueOf(3));
}
 
源代码6 项目: astor   文件: HtmlTreeBuilder.java
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in) {
    int i = queue.lastIndexOf(out);
    Validate.isTrue(i != -1);
    queue.set(i, in);
}
 
源代码7 项目: astor   文件: HtmlTreeBuilder.java
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in) {
    int i = queue.lastIndexOf(out);
    Validate.isTrue(i != -1);
    queue.set(i, in);
}
 
源代码8 项目: astor   文件: HtmlTreeBuilder.java
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in) {
    int i = queue.lastIndexOf(out);
    Validate.isTrue(i != -1);
    queue.set(i, in);
}