Java BeanUtils – Transforming Collections

Java BeanUtils - Transforming Collections

This topic we learned about Java BeanUtils – Transforming Collections.

Description

The conversion from input object to output object is supported in commons-collections with the help of Transformer interface. The Transformers can be applied to get the output collection from input collection with the help of codes available in Commons-collections. BeanToPropertyTransformer is an example of Transformer that will convert a bean to its property value. This feature is able to extract a particular property from the input object and present it as output object.

If you try to find out a particular car model from many car users in a collection. The syntax is shown below:

 
    // creating transformer
     BeanToPropertyValueTransformer transformer = new BeanToPropertyValueTransformer( "person.company.carmodel" );

     // transforming Collection
     Collection carModel = CollectionUtils.collect( peopleCollection, transformer );

In this topic we learned about Java BeanUtils – Transforming Collections. To know more, Click Here.

This Post Has One Comment

Leave a Reply