Basically I have a List<Map<String, Object>> listOfValue
and I need to check if the object is instance of byte then encode it to String as shown below:
private void convertByteToBase64(List<Map<String, Object>> listOfValue) {
Object value = null;
if (!CollectionUtils.isEmpty(listOfValue)) {
for (Map<String, Object> map : listOfValue) {
if (!map.isEmpty()) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
value = entry.getValue();
if (value instanceof byte[]) {
entry.setValue(Base64.getEncoder().encodeToString((byte[]) value));
}
}
}
}
}
}
I am using java 8 and it is working as expected but is it the correct way of doing it or any better way in term of performance?