The technique behind collecting cactus is when a cactus touches a block it pops up.
The things required to make a cactus farm in Minecraft are sand, a bucket of water, a hopper, a chest, some fences and some building blocks (preferably glass), and a bunch of cactus.
Firstly, make a space of 11*11 in your yard where you want to make a cactus farm.
Place building blocks around the dirt in the outermost part to create a square. Building blocks can be anything like wood, stone, dirt.
Dig 3 blocks down in the center and place a chest there. It is a space where the cactus will get collected over time.
Now, place a hopper above the chest.
Place sand all over the inside area, leaving 1 block space from each sand block.
Place two blocks over the sand block so that you can put down a fence in each, then put the fence on the side of the block. This way, when the cactus grows, it will break and fall into the ground.
Repeat the same process on the other edge blocks
Place cactus over the sand block.
Place 4 buckets of water at each corner. Then cover the rest of the farm with glasses 2 blocks high and make a slabs roof over it.
The slabs allow the cactus to grow one block higher and pop up into the water, and the flowing water guides the popped cactus automatically to the hopper leading into the chest. So, this is how you can build an efficient and automatic cactus farm in Minecraft effortlessly.