Java Utililty Methods List Cast

List of utility methods to do List Cast

Description

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

Method

java.util.ListcastListUnchecked(Object list)
cast List Unchecked
return (java.util.List<T>) list;
ListcastNonNullListParameterTo(String parameterName, List value, Class requiredType)
cast Non Null List Parameter To
if (value == null) {
    throw new IllegalArgumentException(parameterName + " is null");
for (T entry : value) {
    if (entry == null) {
        throw new IllegalArgumentException("One entry of " + parameterName + " is null.");
    if (!requiredType.isInstance(entry)) {
...
ListcastOrCopyToList(Iterable iterable)
cast Or Copy To List
if (iterable instanceof List) {
    return (List<E>) iterable;
List<E> list = new ArrayList<E>();
for (E e : iterable) {
    list.add(e);
return list;
...
ListcastTo(final List list, final Class clasz)
cast To
if (isOf(list, clasz)) {
    return (List<E>) list;
throw new IllegalArgumentException("List contains invalid type.");
List>castToDocumentList(Object obj)
Casts the specified object to a List> .
@SuppressWarnings("unchecked")
final List<Map<String, Object>> list = (List<Map<String, Object>>) obj;
return list;
ListcastToList(U[] array, Class clazz)
Convert an array to a list of a different type.
final List<T> res = new ArrayList<T>(array.length);
for (final U item : array) {
    res.add(clazz.cast(item));
return res;
ListcastToStringList(Object value)
cast To String List
List<String> result;
try {
    result = (List<String>) value;
} catch (Exception e) {
    result = null;
if (result == null) {
    return new ArrayList<String>();
...
booleanIS_CASTABLE_LIST(Class className, Object obj)
ICASTABLLIST
if (!(obj instanceof List))
    return false;
for (Object o : (List<?>) obj)
    if (!className.isInstance(o))
        return false;
return true;
StringlistToJsonArray(List ll, Class toCast, String jsonArrayKey)
list To Json Array
StringBuilder temp = new StringBuilder();
try {
    boolean hasData = false;
    Iterator ite = ll.listIterator();
    temp.append("{\"");
    temp.append(jsonArrayKey);
    temp.append("\":[");
    while (ite.hasNext()) {
...
ListtoStringList(List uncastedValues)
to String List
List<String> values = new ArrayList<String>(uncastedValues.size());
for (Object object : uncastedValues) {
    values.add(String.valueOf(object));
return values;