Yes you can if 1) the HDMI swith is mechanical, or 2) the swich has its own power supply. If the switch relies on HDMI power, then you would need auxillary power from a device like this USB adapter.
Choose Apple menu > System Preferences, then click Displays. If your Mac doesn’t recognize a display you’ve just connected, hold down the Option key to make the Detect Displays button appear, then click that button.