本文整理汇总了Java中java.util.ArrayList.lastIndexOf方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayList.lastIndexOf方法的具体用法?Java ArrayList.lastIndexOf怎么用?Java ArrayList.lastIndexOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ArrayList
的用法示例。
在下文中一共展示了ArrayList.lastIndexOf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDuplicateEntries
import java.util.ArrayList; //导入方法依赖的package包/类
/**
* Method looks for the duplicate entry inside the merged Array.
*
* @param mergedArray the merged array
* @param mergedArrayUnique the merged array unique
* @return the duplicate entries
*/
private ArrayList<String> getDuplicateEntries(ArrayList<String> mergedArray, ArrayList<String> mergedArrayUnique ) {
ArrayList<String> returnList = new ArrayList<String>();
for (int i = 0; i < mergedArrayUnique.size(); i++) {
String string = mergedArrayUnique.get(i);
if ( mergedArray.indexOf(string) != mergedArray.lastIndexOf(string) ) {
returnList.add(string);
}
};
return returnList;
}
示例2: main
import java.util.ArrayList; //导入方法依赖的package包/类
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);
}
示例3: replaceInQueue
import java.util.ArrayList; //导入方法依赖的package包/类
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in)
{
int i = queue.lastIndexOf(out);
queue.set(i, in);
}