You can explicitly create a builder:
ImmutableMap<String, Long> oldPrices = ImmutableMap.of("banana", 4, "apple", 7); ImmutableMap<String, Long> newPrices = new ImmutableMap.Builder() .putAll(oldPrices) .put("orange", 9) .build();
EDIT:
As noted in the comments, this will not allow overriding existing values. This can be done by going through the initialization block of another Map (for example, a HashMap ). This is nothing but elegant, but it should work:
ImmutableMap<String, Long> oldPrices = ImmutableMap.of("banana", 4, "apple", 7); ImmutableMap<String, Long> newPrices = new ImmutableMap.Builder() .putAll(new HashMap<>() {{ putAll(oldPrices); put("orange", 9);
source share