Java Utililty Methods List from

List of utility methods to do List from

Description

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

Method

StringlistOf(String type)
list Of
return "java.util.List<" + type + ">";
ListlistOf(T value, int size)
list Of
List<T> list = new ArrayList<T>(size);
list.add(value);
return list;
ArrayListlistOf(T... args)
list Of
ArrayList<T> result = new ArrayList<T>();
for (T t : args)
    result.add(t);
return result;
ListlistOf(T... elements)
list Of
List<T> list = new ArrayList<>();
for (T element : elements) {
    list.add(element);
return list;
ListlistOf(T... elems)
Returns the list of elements given as parameters.
return java.util.Arrays.asList(elems);
ListlistOf(T... values)
list Of
return unmodifiableList(Arrays.asList(values));
ListlistOfArrays(T[]... values)
Simple wrapper for Arrays.asList()
return new ArrayList<T[]>(Arrays.asList(values));
StringlistOfExceptionsAsString(List exs)
Lists exceptions using their toString(), one per line.
StringBuilder sb = new StringBuilder();
for (Exception ex : exs) {
    sb.append(ex.toString()).append("\n");
return sb.toString();
int[]listOfIntegers2ArrayOfInts(List xs)
list Of Integers Array Of Ints
int[] xa = new int[xs.size()];
for (int i = 0; i < xa.length; ++i) {
    xa[i] = xs.get(i);
return xa;
StringlistOfItems(List items, String separator, String finalConjunction)
Return a string that is a list of items separated by separator and using the final conjunction.
final int size = items.size();
if (size < 1)
    return "";
switch (size) {
case 1:
    return items.iterator().next();
case 2:
    return items.get(0) + " " + finalConjunction + " " + items.get(1);
...