Java Utililty Methods Collection Null

List of utility methods to do Collection Null

  1. HOME
  2. Java
  3. C
  4. Collection Null

Description

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

Method

int countNonNull(Collection dist)
count Non Null
int count = 0;
for (Double val : dist) {
 if (val != null) {
 count++;
return count;
int countNotNull(Collection collection)
count Not Null
int i = 0;
for (String item : collection) {
 if (item != null && !"!".equals(toKey(item))) {
 i++;
return i;
T getItemAtPositionOrNull(Collection collection, int position)
Returns the n-th item or null if collection is smaller.
if (position >= collection.size()) {
 return null;
if (collection instanceof List) {
 return ((List<T>) collection).get(position);
Iterator<T> iterator = collection.iterator();
T item = null;
...
int getNextNullIndex(C collection)
get Next Null Index
int output = -1;
int currentLoc = 0;
for (Object object : collection) {
 if (object == null) {
 output = currentLoc;
 break;
 currentLoc++;
...
int getNumberOfNonNullElements(final Collection col)
get Number Of Non Null Elements
if (col == null)
 return 0;
int result = 0;
for (final Object o : col) {
 if (o != null) {
 result++;
return result;
E getSingleElementOrNull(Collection collection)
returns the one and only element of a collection or null if the collection is empty.
if (collection.isEmpty()) {
 return null;
} else if (collection.size() > 1) {
 throw new IllegalStateException("collection has more than one elements");
} else {
 return collection.iterator().next();
int getSizeNullSafe(final Collection collection)
Return the collection's size, or 0 if it is null
return (collection == null) ? 0 : collection.size();
boolean hasAtLeastOneNotNullElement(Collection collection)
has At Least One Not Null Element
if (collection == null)
 return false;
if (collection.isEmpty())
 return false;
if (collection.contains(null))
 return collection.size() > 1;
return collection.size() > 0;
boolean hasCollectionNullItem(Collection collection)
has Collection Null Item
boolean hasNull = false;
Iterator iterator = collection.iterator();
while (iterator.hasNext() && !hasNull) {
 Object object = iterator.next();
 if (object == null) {
 hasNull = true;
return hasNull;
boolean isAllNull(Collection values)
is All Null
boolean status = true;
for (String value : values) {
 if (value != null) {
 status = false;
 break;
return status;
...


AltStyle によって変換されたページ (->オリジナル) /