Java Collection Null getNumberOfNonNullElements(final Collection col)

Here you can find the source of getNumberOfNonNullElements(final Collection col)

Description

get Number Of Non Null Elements

License

Open Source License

Declaration

public static int getNumberOfNonNullElements(final Collection<?> col) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2015, 2017 Lablicate GmbH.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  ww w .  j a v a 2s . co  m
 * Dr. Alexander Kerner - initial API and implementation
 *******************************************************************************/

import java.util.Collection;

public class Main {
    public static int getNumberOfNonNullElements(final Collection<?> col) {

        if (col == null)
            return 0;
        int result = 0;
        for (final Object o : col) {
            if (o != null) {
                result++;
            }
        }
        return result;
    }
}

Related

  1. countNonNull(Collection dist)
  2. countNotNull(Collection collection)
  3. getItemAtPositionOrNull(Collection collection, int position)
  4. getNextNullIndex(C collection)
  5. getSingleElementOrNull(Collection collection)
  6. getSizeNullSafe(final Collection collection)
  7. hasAtLeastOneNotNullElement(Collection collection)
  8. hasCollectionNullItem(Collection collection)