Java Utililty Methods Collection Add

List of utility methods to do Collection Add

Description

The list of methods to do Collection Add are organized into topic(s).

Method

CollectionaddIfNotNull(Collection coll, T value)
Adds a value to the collection if it's not null.
return addIf(coll, value, value != null);
voidaddIfNotNull(Collection listToAddTo, T itemToAddToList, Object objectToCheckIfNull)
Utility method to add an Object to a List if another passed Object is not null
if (objectToCheckIfNull != null) {
    listToAddTo.add(itemToAddToList);
booleanaddIfNotNull(final Collection collection, final V value)
add If Not Null
if (value == null) {
    return false;
} else {
    return collection.add(value);
booleanaddIgnoreNull(Collection collection, Object object)
Adds an element to the collection unless the element is null.
return (object == null ? false : collection.add(object));
booleanaddIgnoreNull(Collection collection, T object)
From Apache commons-collection.
return (object == null ? false : collection.add(object));
booleanaddIgnoreNull(final Collection collection, final T object)
Adds an element to the collection unless the element is null.
if (collection == null) {
    throw new NullPointerException("The collection must not be null");
return object != null && collection.add(object);
StringBuilderaddInClauseToQuery(StringBuilder query, Collection l)
add In Clause To Query
query.append(" (");
for (Iterator<Object> i = l.iterator(); i.hasNext();) {
    Object columnValue = i.next();
    if (columnValue instanceof String) {
        columnValue = "'" + columnValue + "'";
    query.append(columnValue).append(i.hasNext() ? "," : "");
query.append(")");
return query;
voidaddItem(Collection collection, Object item)
add Item
((Collection) collection).add(item);
voidaddMatchingStrings(Collection availableProperties, String startWith, Collection strings)
add Matching Strings
for (String string : strings)
    if (string.startsWith(startWith))
        availableProperties.add(string);
CollectionaddNewLines(Collection strings)
add New Lines
if (strings.size() < 5)
    return strings;
List<String> result = new ArrayList<>();
int counter = 0;
for (String string : strings) {
    if (counter > 0 && counter % 4 == 0) {
        result.add("\n" + string);
    } else {
...