Returns a list that applies
function to each element of
fromList. The returned list is a transformed view of
fromList;
changes to
fromList will be reflected in the returned list and vice
versa.
Since functions are not reversible, the transform is one-way and new
items cannot be stored in the returned list. The
add,
addAll and
set methods are unsupported in the returned
list.
The function is applied lazily, invoked when needed. This is necessary
for the returned list to be a view, but it means that the function will be
applied many times for bulk operations like
List#contains and
List#hashCode. For this to perform well,
function should be
fast. To avoid lazy evaluation when the returned list doesn't need to be a
view, copy the returned list into a new list of your choosing.
If
fromList implements
RandomAccess, so will the
returned list. The returned list is threadsafe if the supplied list and
function are.
If only a
Collection or
Iterable input is available, use
Collections2#transform or
Iterables#transform.
Note: serializing the returned list is implemented by serializing
fromList, its contents, and
function -- not by
serializing the transformed values. This can lead to surprising behavior,
so serializing the returned list is not recommended. Instead,
copy the list using
ImmutableList#copyOf(Collection) (for example),
then serialize the copy. Other methods similar to this do not implement
serialization at all for this reason.
Java 8 users: many use cases for this method are better addressed
by
java.util.stream.Stream#map. This method is not being
deprecated, but we gently encourage you to migrate to streams.