Java Utililty Methods List Subtract

List of utility methods to do List Subtract

Description

The list of methods to do List Subtract are organized into topic(s).

Method

Listsubtract(final List list1, final List list2)
Subtracts all elements in the second list from the first list, placing the results in a new list.
final ArrayList result = new ArrayList(list1);
final Iterator iterator = list2.iterator();
while (iterator.hasNext()) {
    result.remove(iterator.next());
return result;
Listsubtract(final List list1, final List list2)
Subtracts all elements in the second list from the first list, placing the results in a new list.
final ArrayList result = new ArrayList(list1);
final Iterator iterator = list2.iterator();
while (iterator.hasNext()) {
    result.remove(iterator.next());
return result;
voidsubtract(final List result, final Object o1, final Object o2)
subtract
final Number val1 = (Number) o1;
final Number val2 = (Number) o2;
result.add(val1.doubleValue() - val2.doubleValue());
String[]subtract(final String[] input, final String[] list)
Subtract one string array from another
final Set<String> difference = new HashSet<String>(Arrays.asList(list));
difference.removeAll(Arrays.asList(input));
return difference.toArray(new String[difference.size()]);
Listsubtract(List a, List b)
Vector subtraction Modifies the first parameter but also returns it for convenience.
if (a.size() != b.size()) {
    throw new IllegalArgumentException(
            "Length of vector a (" + a.size() + ") does not equal length of vector b (" + b.size() + ")");
List<Float> c = new ArrayList<Float>();
for (int i = 0; i < a.size(); i++) {
    c.add(a.get(i) - b.get(i));
return c;
Listsubtract(List vector, int[] sparseVector)
subtract
List<Integer> result = new ArrayList<Integer>(vector);
for (int offset : sparseVector) {
    if (offset == -1) {
        continue;
    result.set(offset, result.get(offset) - 1);
return result;
...
Listsubtract(List a, List b)
subtract
List<String> result = new ArrayList<>(a);
result.removeAll(b);
return result;
Listsubtract(List aList, List bList)
subtract
List<T> result = new ArrayList<T>();
for (T t : aList) {
    if (!bList.contains(t)) {
        result.add(t);
return result;
String[]subtract(String[] list1, String[] list2)
Remove Strings that are in list2 from list1.
ArrayList diff = new ArrayList(list1.length);
boolean add = true;
for (int i = 0; i < list1.length; i++) {
    for (int j = 0; j < list2.length; j++) {
        if (list1[i].equals(list2[j])) {
            add = false;
            break;
    if (add)
        diff.add(list1[i]);
    add = true;
return arrayListToStringArray(diff);
ListsubtractAsList(T[] array1, T[] array2)
subtract As List
List<T> list = new ArrayList<>(Arrays.asList(array1));
list.removeAll(Arrays.asList(array2));
return list;