下面列出了java.util.ArrayList#lastIndexOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
public void test3NoBugs(ArrayList<? extends CharSequence> list) {
list.lastIndexOf(new StringBuffer("Key"));
}
public void test3Bugs(ArrayList<? extends CharSequence> list) {
list.lastIndexOf(Integer.valueOf(3));
}
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in) {
int i = queue.lastIndexOf(out);
Validate.isTrue(i != -1);
queue.set(i, in);
}
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in) {
int i = queue.lastIndexOf(out);
Validate.isTrue(i != -1);
queue.set(i, in);
}
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in) {
int i = queue.lastIndexOf(out);
Validate.isTrue(i != -1);
queue.set(i, in);
}