@SuppressWarnings("unchecked")
    private static Collection<?> prepareIndexedCollectionType(Class<?> collectionType, Object existingCollection,
                                                              Object collectionEntry, int index) {
        Collection result = null;
        //Instantiation of the new Collection: can be interface or implementation class
        if (collectionType.isInterface()) {
            if (collectionType.equals(Set.class)) {
                result = new HashSet();
            } else if (collectionType.equals(List.class)) {
                result = new ArrayList();
            } else {
                throwMappingException("Only interface types java.util.Set and java.util.List are supported for java.util.Collection type indexed properties.");
            }
        } else {
            //It is an implementation class of Collection
            try {
                result = (Collection)collectionType.newInstance();
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }

        //Fill in old values in new Collection
        if (existingCollection != null) {
            result.addAll((Collection)existingCollection);
        }

        //Add the new value:
        //For an ordered Collection
        if (result instanceof List) {
            while (result.size() < index + 1) {
                result.add(null);
            }
            ((List)result).set(index, collectionEntry);
        } else {
            //for an unordered Collection (index has no use here)
            result.add(collectionEntry);
        }
        return result;
    }
Internal class that provides various mapping utilities used throughout the code base. Only intended for internal use.
core/src/main/java/com/github/dozermapper/core/util/MappingUtils.java