Minecraft wiki entry for replaceitem, associated text: To replace the items in the bottom-right slot of a single chest two block above with four spruce saplings:
replaceitem block ~ ~2 ~ slot.container 26 sapling 4 1
To replace the items in the rightmost hotbar slot of the nearest player with four spruce saplings:
replaceitem entity @p slot.hotbar 8 sapling 4 1