Java Utililty Methods List First Item

List of utility methods to do List First Item

Description

The list of methods to do List First Item are organized into topic(s).

Method

ObjectgetFirstInstanceOf(List source, String className)
get First Instance Of
Class targetInstance = Class.forName(className);
if (findInstanceOfClassExists(source, className)) {
    for (Object object : source) {
        if (targetInstance.isInstance(object))
            return targetInstance.cast(object);
return null;
...
StringgetFirstItemOrNull(List items)
get First Item Or Null
return items == null || items.size() == 0 ? null : items.get(0);
ObjectgetFirstLeaf(List aList)
Returns the first non-list object in the given list hierarchy, recursing if a list is found.
for (int i = 0, iMax = aList.size(); i < iMax; i++) {
    Object obj = aList.get(i);
    if (obj instanceof List)
        obj = getFirstLeaf((List) obj);
    if (obj != null)
        return obj;
return null;
...
intgetFirstNameIndex(List list)
get First Name Index
for (int i = 0; i < list.size(); i++) {
    if ((list.get(i).length() > 1) && (!personStopWordSet.contains(list.get(i)))) {
        return i;
return -1;
intgetFirstNonEmptyIndex(final List> list)
get First Non Empty Index
for (int i = 0; i < list.size(); i++) {
    final Collection<?> o = list.get(i);
    if (o != null && !o.isEmpty()) {
        return i;
return -1;
StringgetFirstObject(List valueList)
Get the String value Stored on the 0 index of specified List.
try {
    return valueList.get(0).toString();
} catch (Exception e) {
    return null;
StringgetFirstOccurNic(List nics, String line)
get First Occur Nic
int idx = Integer.MAX_VALUE;
String result = "";
for (String nic : nics) {
    int i = line.indexOf(nic);
    if ((i >= 0) && (i < idx)) {
        idx = i;
        result = nic;
return result;
TgetFirstOrNull(List elements)
get First Or Null
return elements.isEmpty() ? null : elements.get(0);
TgetFirstOrNull(List list)
Return the first element of list.
if (list == null || list.isEmpty()) {
    return null;
return list.get(0);
T[]getFirstRowMatch(List list, int columnIndex, T value)
get First Row Match
for (T[] rows : list) {
    if (rows[columnIndex].equals(value))
        return rows;
return null;