List of usage examples for java.util ArrayList lastIndexOf
public int lastIndexOf(Object o)
From source file:Main.java
public static void main(String[] args) { ArrayList<String> arrlist = new ArrayList<String>(5); arrlist.add("G"); arrlist.add("E"); arrlist.add("F"); arrlist.add("M"); arrlist.add("E"); arrlist.add("from java2s.com"); System.out.println("Size of list: " + arrlist.size()); System.out.println(arrlist);//from w w w . ja v a 2 s. c o m // Retrieving the index of last occurrence of element "E" int retval = arrlist.lastIndexOf("E"); System.out.println("The last occurrence of E is at index " + retval); }
From source file:Main.java
public static void main(String[] args) { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("2"); arrayList.add("2"); arrayList.add("3"); arrayList.add("4"); arrayList.add("5"); arrayList.add("1"); arrayList.add("2"); System.out.println(arrayList.contains("2")); int index = arrayList.indexOf("4"); if (index == -1) System.out.println("not contain 4"); else//from w w w . ja v a 2s . c om System.out.println("4 at index :" + index); int lastIndex = arrayList.lastIndexOf("1"); if (lastIndex == -1) System.out.println("not contain 1"); else System.out.println("Last index :" + lastIndex); }
From source file:com.draagon.meta.manager.ObjectManager.java
/** * Clips the specified objects by the provided range *///from w w w.jav a 2s . com public static Collection<Object> distinctObjects(Collection<?> objs) throws MetaException { // TODO: Check this, as I don't think it works! ArrayList<Object> a = new ArrayList<Object>(objs); for (Iterator<Object> i = a.iterator(); i.hasNext();) { Object o = i.next(); // Find the first index of the object int fi = a.indexOf(o); // Remove all objects of the same value int li = 0; while ((li = a.lastIndexOf(o)) != fi) a.remove(li); } return a; }
From source file:com.stratelia.webactiv.beans.admin.Admin.java
private ArrayList<String> removeTuples(ArrayList<String> al) { if (al == null) { return new ArrayList<String>(); }//from w w w .j a v a2s .c o m for (int nI = 0; nI < al.size(); nI++) { while (al.lastIndexOf(al.get(nI)) != al.indexOf(al.get(nI))) { al.remove(al.lastIndexOf(al.get(nI))); } } return al; }
From source file:org.openadaptor.auxil.convertor.fixedwidth.AbstractFixedWidthStringConvertor.java
/** * @return false if the field name supplied is null or an empty string * /*ww w . j av a 2 s .c o m*/ * @throws ValidationException * if there are multiple fields defined with the same name */ public boolean isValidFieldName(String name) { ArrayList names = getFieldNames(); int a = names.indexOf(name); int b = names.lastIndexOf(name); if (a != b) throw new ValidationException("Multiple field names defined", this); return (name != null && !name.equals("")); }
From source file:org.silverpeas.core.admin.service.Admin.java
private ArrayList<String> removeTuples(ArrayList<String> al) { if (al == null) { return new ArrayList<>(); }/*from w w w . java 2 s. co m*/ for (int nI = 0; nI < al.size(); nI++) { while (al.lastIndexOf(al.get(nI)) != al.indexOf(al.get(nI))) { al.remove(al.lastIndexOf(al.get(nI))); } } return al; }