當前位置: 首頁>>代碼示例>>Java>>正文


Java ArrayList.lastIndexOf方法代碼示例

本文整理匯總了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;
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:18,代碼來源:OntologyVisualisationHelper.java

示例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);
  }
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:47,代碼來源:SearchAnElementInArrayListExample.java

示例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);
}
 
開發者ID:skeychen,項目名稱:dswork,代碼行數:6,代碼來源:TreeBuilderHtml.java


注:本文中的java.util.ArrayList.lastIndexOf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。