How do I programmatically set the preferred language for a user? I would like to update the preferred_langcode of a user as soon as he changes the language in a language switcher block.

I'm already aware of the getPreferredLangcode method mentioned in https://api.drupal.org/api/drupal/core!modules!user!src!Entity!User.php/function/User%3A%3AgetPreferredLangcode/8.6.x and looking for a setPreferredLangcode method, if one exists.

If not, what other options do I have?
Seems D8 doesn't have a setPreferredLangcode method yet. So, the preferred approach IMHO would be to use the default set method of D8 Entity API as below
$user = \Drupal\user\Entity\User::load('uid');
$user-&gt;set('preferred_langcode', 'en or whatever langcode we want');
$user-&gt;save();