How to remove an item from the stack?

setQuantity should work fine. Perhaps you could give us more context for what you’re doing (and provide code samples).
For example, if the ItemStack came from an inventory, you need to give the inventory the new item stack back (because inventories deal with copies of stacks).