Both work. What matters is choosing one and sending everything to it.
Why it matters
example.com and www.example.com are technically different addresses. Serve the same site at both and you split your search ranking between them, confuse caching and analytics, and can create duplicate-content problems.
Picking one
Neither is better. Without www is shorter and now more common; with it is more traditional, and slightly more flexible at the DNS level because it can be a CNAME. If your site is already established on one, stay there - the switch costs more than it gains.
Setting it up
- Make sure both names resolve to your hosting.
- Set the site's own address setting to your chosen version.
- Redirect the other to it with a 301.
- Make sure the certificate covers both names.
Do the same for HTTPS
Combine the two: redirect straight to https:// and your chosen form in a single hop, rather than chaining redirects. Fewer hops is faster and less fragile.
Check it
Try all four combinations - with and without www, over HTTP and HTTPS. Each should land on your chosen address with no warning and no loop.