cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

What is difference between convert and convertAll method

Hari_prasad
Participant
0 Likes
1,194

Hi experts,

I am going through populators and converters, there are two methods in converter "convert and convertAll, What is the difference between them?

Accepted Solutions (1)

Accepted Solutions (1)

mansurarisoy
Contributor

convert() method converts only a single source to a target object, while convertAll() method converts a list of sources and returns a list of converted target objects. convertAll() uses convert() method inside to convert each object in the source list.

Default implementation of the convertAll() method is as follows in the Converter.class interface

 default List<TARGET> convertAll(Collection<? extends SOURCE> sources) throws ConversionException {
     if (CollectionUtils.isEmpty(sources)) {
         return Collections.emptyList();
     } else {
         List<TARGET> result = new ArrayList(sources.size());
         Iterator var4 = sources.iterator();
 
         while(var4.hasNext()) {
             SOURCE source = (Object)var4.next();
             result.add(this.convert(source));
         }
 
         return result;
     }
 }

So, actually there is no significant difference between these two methods. Only difference is that convertAll() methods simplifies converting a list of objects.

Regards,
Mansur

Answers (0)