Player Inventory set/get

Hello everyone, I’m trying to save a player’s inventory when he changes gamemod.

For that, during the ChangeGameModeEvent.TargetPlayer event, I add to a static HashMap in the same class as the event, the name and the inventory like this
hashInv.put(target.getName(),target.getInventory());

I also make sure that the inventory is not empty at the moment of its recovery.
Then during the change of after, I wish to return the inventory to the player. But I do not know the method to set an inventory.
To be with the method query?

target.getInventory()......

Thanks for your help !