List of usage examples for java.util List remove
E remove(int index);
From source file:Main.java
public static List<Element> getChildrenWithTag(Element parent, String tag) { List<Element> list = getElementChildren(parent); for (Element e : list.toArray(new Element[0])) { if (!e.getTagName().equals(tag)) list.remove(e); }//from ww w .j a v a 2 s . co m return list; }
From source file:Main.java
public static void copyList() { List<Integer> l = new ArrayList<Integer>(); l.add(1);/*from w w w . j a v a2 s .co m*/ l.add(2); l.add(3); l.add(4); List<Integer> lCopy = new ArrayList<Integer>(l); l.remove(0); System.out.println(l); System.out.println(lCopy); }
From source file:Main.java
public static <T> void removeDuplicate(List<T> list) { for (int i = 0; i < list.size(); i++) { for (int j = i + 1; j < list.size(); j++) { if (list.get(i).equals(list.get(j))) { list.remove(j); }/*w ww. java2s . co m*/ } } }
From source file:com.yahoo.labs.samoa.topology.impl.StormTopologySubmitter.java
private static String uploadedJarLocation(List<String> tmpArgs) { int position = tmpArgs.size() - 1; String uploadedJarLocation = tmpArgs.get(position); tmpArgs.remove(position); return uploadedJarLocation; }
From source file:Main.java
/** * Internal function to realize the mathematical combination of given * values. This method creates the next sub-tree by iterating over values * given by parameter set./* ww w. j av a2s .c om*/ * * @param <E> * the type of the given and returned values * @param list * the possible values for next iteration * @param combination * the current path of the abstract combination tree * @param combinations * overall combinations */ private static <E extends Object> void combination(List<E> list, List<E> combination, List<List<E>> combinations) { for (E value : list) { List<E> combination_ = new LinkedList<E>(); combination_.addAll(combination); combination_.add(value); combinations.add(combination_); List<E> list_ = new LinkedList<E>(); list_.addAll(list); list_.remove(list); if (!list_.isEmpty()) { combination(list_, combination_, combinations); } } }
From source file:Main.java
@SafeVarargs public static <T> boolean contains(T[] array, T... toLookFor) { if (array == null) return false; List<T> searchList = new ArrayList<>(Arrays.asList(toLookFor)); for (T element : array) { if (searchList.contains(element)) { searchList.remove(element); }//from www. j a va 2 s . c om if (searchList.size() == 0) { return true; } } return false; }
From source file:Main.java
@SuppressWarnings("rawtypes") public static final List chopList(List list) { if (null == list) { return null; } else {//from www .j a va 2s.c om for (int i = 0; i < list.size(); i++) { if (null == list.get(i)) { list.remove(i); i--; } } return list; } }
From source file:Main.java
public static <T> List<T> getRandomDistinctElements(final Random random, final List<T> list, final int nElements) { if (list.size() < nElements) throw new IllegalArgumentException("cannot sample " + nElements + " elements from " + list.size()); // TODO: avoid creating "bowl" collection final List<T> bowl = new ArrayList<T>(list); final List<T> sample = new ArrayList<T>(nElements); for (int i = 0; i < nElements; i++) { sample.add(bowl.remove(random.nextInt(bowl.size()))); }/*from w w w . j a v a2 s .c o m*/ return sample; }
From source file:Main.java
@SuppressWarnings("unchecked") public static final List chopList(List list) { if (null == list) { return null; } else {/*from w w w .j a va 2 s . c o m*/ for (int i = 0; i < list.size(); i++) { if (null == list.get(i)) { list.remove(i); i--; } } return list; } }
From source file:Main.java
public static <T> void removeAll(List<? extends T> removeFrom, List<? super T> c2) { for (Object o : c2) { for (int i = 0; i < removeFrom.size(); i++) { if (o.equals(removeFrom.get(i))) { removeFrom.remove(i); }//from w w w . j a v a 2s .c o m } } }