当前位置: 首页>>代码示例>>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;未经允许,请勿转载。