java.lang.Object | +--org.apache.commons.collections.ListUtils
static List | An empty unmodifiable list. |
ListUtils should not normally be instantiated. |
static List | fixedSizeList(List list) Returns a fixed-sized list backed by the given list. |
static int | hashCodeForList(final Collection list) Generates a hash code using the algorithm specified in java.util.List#hashCode(). |
static List | intersection(final List list1, final List list2) Returns a new list containing all elements that are contained in both given lists. |
static boolean | isEqualList(final Collection list1, final Collection list2) Tests two lists for value-equality as per the equality contract in java.util.List#equals(java.lang.Object). |
static List | lazyList(List list, Factory factory) Returns a "lazy" list whose elements will be created on demand. |
static List | predicatedList(List list, Predicate predicate) Returns a predicated list backed by the given list. |
static List | subtract(final List list1, final List list2) Subtracts all elements in the second list from the first list, placing the results in a new list. |
static List | sum(final List list1, final List list2) Returns the sum of the given lists. |
static List | synchronizedList(List list) Returns a synchronized list backed by the given list. |
static List | transformedList(List list, Transformer transformer) Returns a transformed list backed by the given list. |
static List | typedList(List list, Class type) Returns a typed list backed by the given list. |
static List | union(final List list1, final List list2) Returns a new list containing the second list appended to the first list. |
static List | unmodifiableList(List list) Returns an unmodifiable list backed by the given list. |
public static final List EMPTY_LIST
public ListUtils()
ListUtils
should not normally be instantiated.
public static List fixedSizeList(List list)
- if the List is nullpublic static int hashCodeForList(final Collection list)
List
when you cannot
extend AbstractList. The method takes Collection instances to enable other
collection types to use the List implementation algorithm.
java.util.List.hashCode()
public static List intersection(final List list1, final List list2)
- if either list is nullpublic static boolean isEqualList(final Collection list1, final Collection list2)
List
when you cannot
extend AbstractList. The method takes Collection instances to enable other
collection types to use the List implementation algorithm.
The relevant text (slightly paraphrased as this is a static method) is:
Compares the two list objects for equality. Returns true if and only if both lists have the same size, and all corresponding pairs of elements in the two lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two lists are defined to be equal if they contain the same elements in the same order. This definition ensures that the equals method works properly across different implementations of the List interface.Note: The behaviour of this method is undefined if the lists are modified during the equals comparison.
java.util.List
public static List lazyList(List list, Factory factory)
Factory factory = new Factory() { public Object create() { return new Date(); } } List lazy = ListUtils.lazyList(new ArrayList(), factory); Object obj = lazy.get(3);After the above code is executed,
obj
will contain
a new Date
instance. Furthermore, that Date
instance is the fourth element in the list. The first, second,
and third element are all set to null
.
- if the List or Factory is nullpublic static List predicatedList(List list, Predicate predicate)
- if the List or Predicate is nullpublic static List subtract(final List list1, final List list2)
list1
contains two
occurrences of null
and list2
only
contains one occurrence, then the returned list will still contain
one occurrence.
- if either list is nullpublic static List sum(final List list1, final List list2)
- if either list is nullpublic static List synchronizedList(List list)
List list = ListUtils.synchronizedList(myList); synchronized (list) { Iterator i = list.iterator(); while (i.hasNext()) { process (i.next()); } }This method uses the implementation in the decorators subpackage.
- if the list is nullpublic static List transformedList(List list, Transformer transformer)
- if the List or Transformer is nullpublic static List typedList(List list, Class type)
public static List union(final List list1, final List list2)
- if either list is nullpublic static List unmodifiableList(List list)
- if the list is null