Java Utililty Methods List Single Value

List of utility methods to do List Single Value

Description

The list of methods to do List Single Value are organized into topic(s).

Method

Tsingle(List list)
single
if (list.size() == 1) {
    return list.get(0);
} else if (list.size() == 0) {
    throw new RuntimeException("No results found!");
} else {
    throw new RuntimeException("More results returned than one!");
ListsingleElementList(T element)
single Element List
List<T> newElementList = new ArrayList<>(1);
newElementList.add(element);
return newElementList;
ArrayListsingleItemAsList(T item)
Puts the single item inside newly created ArrayList and returns this list.
ArrayList<T> list = new ArrayList<T>();
list.add(item);
return list;
ListsingleQuoatanizeStringList(List entries)
Place single quotes around the individual entries in a List of Strings
List<String> quotedEntries = new ArrayList<String>(entries == null ? 0 : entries.size());
if (entries != null) {
    for (Iterator<String> iterator = entries.iterator(); iterator.hasNext();) {
        String entry = (String) iterator.next();
        quotedEntries.add("'" + entry + "'");
return quotedEntries;
...
ListsingletonList(final T source)
singleton List
return Collections.singletonList(source);
ListsingletonList(T element)
Replies a singleton list with the given element, or the empty list if the element is null.
if (element == null) {
    return Collections.emptyList();
return Collections.singletonList(element);
ListsingletonListIfNotNullOrEmptyListIfNull(T element)
singleton List If Not Null Or Empty List If Null
if (element == null) {
    return new LinkedList<T>();
} else {
    return list(element);
TsingleValue(Class type, List values)
single Value
if (null == values || values.size() != 1) {
    throw new IllegalStateException("Expecting a single value");
return type.cast(values.get(0));
TsingleValue(List l)
single Value
if (l == null || l.isEmpty())
    return null;
else
    return (T) l.get(0);
TsingleValue(List values)
single Value
return values == null || values.isEmpty() ? null : values.get(0);