In a hub, all the ports are electrically connected, and only one device at a time can talk on the wire. If more then one talkdevice talks at the same time, it creates a collision. That's why, so hub connections must beports are all half-duplex.
In a switch, each port is isolated, and traffic from one port is selectively sent to other ports;ports, so there are no collisions in the switch. Unlike a hub, where all the ports together are in one collision domain, on a switch, each switch port is a separate collision domain. That means that each switch port can be set to full-duplex (when connected to a single device supporting full-duplex) or half-duplex (when connected to a hub or other device requiring half-duplex).