Let’s say I have a bean like below.
class Customer{
private String code;
private String name;
private Integer value;
//getters setters omitted for brevity
}
Then from a method I get a List<Customer> back. Now let’s say I want to get a list of all member “name” from the List. Obviously I can traverse and build a List<String> of element “name” myself.
However, I was wondering if there is a short cut or more effiecient way to this technique that anyone knows . For instance, if I want to get a list of all keys in a Map object I get do map.keySet(). Something along that line is what I am trying to find out.
Guava has
Lists.transformthat can transform aList<F>to aList<T>, using a providedFunction<F,T>(or rather,Function<? super F,? extends T>).From the documentation:
Similar live-view transforms are also provided as follows:
Iterables.transform(Iterable<F>toIterable<T>)Iterators.transform(Iterator<F>toIterator<T>)Collections2.transform(Collection<F>toCollection<T>)Maps.transformValues(Map<K,V1>toMap<K,V2>)