Java Code Examples for java.util.ArrayList#lastIndexOf()

The following examples show how to use java.util.ArrayList#lastIndexOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FocusFinder.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: SearchAnElementInArrayListExample.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
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);
  }
 
Example 3
Source File: SearchAnElementInArrayListExample.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
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);
    }
 
Example 4
Source File: ListTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test3NoBugs(ArrayList<? extends CharSequence> list) {
    list.lastIndexOf(new StringBuffer("Key"));
}
 
Example 5
Source File: ListTests.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void test3Bugs(ArrayList<? extends CharSequence> list) {
    list.lastIndexOf(Integer.valueOf(3));
}
 
Example 6
Source File: HtmlTreeBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in) {
    int i = queue.lastIndexOf(out);
    Validate.isTrue(i != -1);
    queue.set(i, in);
}
 
Example 7
Source File: HtmlTreeBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in) {
    int i = queue.lastIndexOf(out);
    Validate.isTrue(i != -1);
    queue.set(i, in);
}
 
Example 8
Source File: HtmlTreeBuilder.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in) {
    int i = queue.lastIndexOf(out);
    Validate.isTrue(i != -1);
    queue.set(i, in);
}