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

The following are Jave code examples for showing how to use lastIndexOf() of the java.util.ArrayList class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: AgentWorkbench   File: OntologyVisualisationHelper.java   Source Code and License Vote up 5 votes
/**
 * 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;
}
 
Example 2
Project: javaide   File: SearchAnElementInArrayListExample.java   Source Code and License Vote up 4 votes
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
Project: dswork   File: TreeBuilderHtml.java   Source Code and License Vote up 4 votes
private void replaceInQueue(ArrayList<Element> queue, Element out, Element in)
{
	int i = queue.lastIndexOf(out);
	queue.set(i, in);
}