Java Collection Add addIf(Collection coll, T value, boolean expr)

Here you can find the source of addIf(Collection coll, T value, boolean expr)

Description

Adds a value to the collection if the boolean expression is true.

License

Apache License

Declaration

public static <T> Collection<T> addIf(Collection<T> coll, T value, boolean expr) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.Collection;

public class Main {
    /**//from   w  w w  .j a va 2  s  .c  o  m
     *  Adds a value to the collection if the boolean expression is true.
     *  Returns the collection as a convenience for chained invocations.
     *
     *  @since 1.0.8
     */
    public static <T> Collection<T> addIf(Collection<T> coll, T value, boolean expr) {
        if (expr)
            coll.add(value);

        return coll;
    }
}

Related

  1. addCondition(Collection conditions, String condition, double value)
  2. addConditionImpl(Collection conditions, String condition, String value)
  3. addDirToStringPaths(Collection ss, String dir)
  4. added(Collection old, Collection nu)
  5. added(Collection a, Collection b)
  6. addIfAbsent(Collection c, T item)
  7. addIfMissing(Collection result, Iterable addition)
  8. addIfNotContains(Collection collection, T value)
  9. addIfNotEmpty(Collection c, Collection elements)