Nextcloud change domain url from example.com/nextcloud to example.com/

For sure. Assign any trusted domain you own. example.com is totally fine.

or, Read the documentation at:

https://docs.nextcloud.com/server/latest/admin_manual/

Search similar questions on this forum, or the greater internet for this question. Lots of good info out there.

You will need to own the domain you use. Once you tell nextcloud to look for that domain you are good to go (as far as Nextcloud itself is concerned). Check your domain registrar if more work is needed. Cheers!