It’s more or less the same Maciek @maciekkreft ,
but Linking Materials is usually faster…and you are linking all Material Slots at the same time…
The Cube has 6 Materials and the Monkey has Material slots 1, 2 and 3 assigned and the Torus slots 4, 5 and 6:

Link Materials does this:

(Not a very practical example, I know.)