on ‎2019 Jun 29 11:44 AM
Hi experts,
I am going through populators and converters, there are two methods in converter "convert and convertAll, What is the difference between them?
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.