List of usage examples for java.util List remove
E remove(int index);
From source file:Main.java
public static <T> List<T> subtract(final Collection<T> a, final Collection<T> b) { List<T> list = new ArrayList<T>(a); for (T element : b) { list.remove(element); }//from w w w . j av a2s. com return list; }
From source file:com.textocat.textokit.commons.util.TrainDevTestCorpusSplitter.java
private static <T> T getAndRemove(List<T> list, int index) { T result = list.get(index);// ww w . ja va2 s.c o m list.remove(index); return result; }
From source file:Main.java
public static void removeRange(List list, int start, int count) { for (int i = start + count - 1; i >= start; i--) { list.remove(i); }// ww w . j a va 2 s . c om }
From source file:Main.java
public static <E> E removeReplace(List<E> list, int index) { int lastIdx = list.size() - 1; E last = list.remove(lastIdx); if (lastIdx != index) { list.set(index, last);//from w ww.j av a2s . c om return last; } return null; }
From source file:Main.java
public static <E> E removeIfInBounds(final List<E> list, final int index) { return (list != null) && (index >= 0) && (index < list.size()) ? list.remove(index) : null; }
From source file:Main.java
public static List<String> merge(final List<String> list, final int index) { if (list.isEmpty()) { throw new IndexOutOfBoundsException("Cannot merge empty list"); } else if (index + 1 >= list.size()) { throw new IndexOutOfBoundsException("Cannot merge last element"); } else {//from ww w.j a v a 2s .c o m final List<String> result = new ArrayList<String>(list); result.set(index, list.get(index) + list.get(index + 1)); result.remove(index + 1); return result; } }
From source file:Main.java
public static <E> void removeLast(List<E> list) { if (isEmpty(list)) { return;//from ww w .ja v a 2 s. c om } list.remove(list.size() - 1); }
From source file:Main.java
@Nullable public static <ELEMENTTYPE> ELEMENTTYPE removeFirstElement(@Nullable final List<ELEMENTTYPE> aList) { return isEmpty(aList) ? null : aList.remove(0); }
From source file:Main.java
/** * Remove an element from a map whose values are lists of elements. * @param <T> the type of the keys in the map. * @param <U> the type of the elements in the lists. * @param key the key for the value to remove. * @param value the value to remove./*from w w w.j a v a 2s . co m*/ * @param map the map from which to remove the key/value pair. */ public static <T, U> void removeFromListMap(T key, U value, Map<T, List<U>> map) { List<U> list = map.get(key); if (list == null) return; list.remove(value); if (list.isEmpty()) map.remove(key); }
From source file:Main.java
private static <T> T remove(List<T> list, int position) { if (list.isEmpty()) return null; return list.remove(position); }