If you are holding a totem of undying in both hands, the one in your offhand will be used first. In Java Edition, items in the main hand are preferred over items in the offhand.
- Get 2 totems of undying, and put one in your offhand and one in your main hand. Make sure that the currently-selected hotbar slot is the one with the totem.
- Switch to survival mode.
- Do something that would normally kill you, in order to activate one of the totems.
- Notice that the totem of undying in your offhand is used instead of the one in your main hand.