Yes, there is only a small modification:
for (Record record : collection.getArrayList()) if (existingIds.put(record.getID(), vo.getID()) != null) throw new BusinessException("records must be unique.", ExceptionCodes.RECORDS_MUST_BE_UNIQUE);
Operation
A Map .put() returns the previous value for the key. If there was no record, null returned. And here, since you do not have null values, this means that if the return code is NOT null , you have a duplicate.
(also why a LinkedHashMap ? Your method returns void , so the insertion order doesn't matter, just use a HashMap )
(also, as suggested, when building a map, initialize its size to the size of the collection that you are checking)
source share