Java Utililty Methods List Null Empty

List of utility methods to do List Null Empty

Description

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

Method

ListgetEmptyList(Class tClass)
get Empty List
return Collections.unmodifiableList(new ArrayList<T>(0));
TgetIgnoreNull(List list, int n)
get Ignore Null
int cnt = 0;
for (T i : list)
    if (i != null) {
        if (cnt == n)
            return i;
        cnt++;
return null;
...
ListgetListIgnoringNulls(T[] items)
get List Ignoring Nulls
if (items == null) {
    return null;
List<T> results = new ArrayList<T>();
for (T next : items) {
    if (next != null) {
        results.add(next);
if (results.size() == 0) {
    return null;
return results;
ListgetNonNull(List list)
get Non Null
if (list == null) {
    return Collections.emptyList();
return list;
intgetNotNullCount(List list)
get Not Null Count
if (list == null) {
    return 0;
int count = 0;
for (Object obj : list) {
    if (obj != null) {
        count++;
return count;
ListgetNotNullId(final List idList)
get Not Null Id
List<Long> result = new ArrayList<Long>();
if (idList == null || idList.isEmpty())
    return result;
for (Long id : idList)
    if (id != null)
        result.add(id);
return result;
StringgetScreen_BL_NONNULL(List searchableFields)
get ScreeBNONNULL
return getHTML_BL(searchableFields);
ListgetSearchTermIndexLocationsOrNull(final List pageWords, final String searchTerm)
get Search Term Index Locations Or Null
String[] tokanizedSearchTerm = getTokanizedSearchTerm(searchTerm.toUpperCase());
List<Integer> indexLocations = new ArrayList<Integer>();
for (int i = 0; i < pageWords.size(); i++) {
    for (String token : tokanizedSearchTerm) {
        if (token.equals(pageWords.get(i))) {
            indexLocations.add(i);
return indexLocations;
ListgetStringAsList(String input, String regexSplitter, boolean ignoreEmptyTokens)
get String As List
List<String> results = new ArrayList<String>();
if (input == null) {
    return results;
for (String lineItem : input.split(regexSplitter)) {
    if (ignoreEmptyTokens && lineItem.trim().equals("")) {
        continue;
    results.add(lineItem);
return results;
ListimmutableListOfType(List list, Class type, boolean nullOk)
immutable List Of Type
List<Object> l = new ArrayList<Object>(list.size());
for (Iterator iter = list.iterator(); iter.hasNext();) {
    Object item = iter.next();
    if (item == null) {
        if (!nullOk) {
            throw new NullPointerException("item of list is null");
    } else if (!type.isInstance(item)) {
...