How to build an automatic sugar cane farm in Minecraft
Put one Minecart with Hopper on each rail.

The Minecart with Hopper sucks up items lying above it, even through a block, and unloads into a hopper below the rail. It is a Minecart carrying a block, which rolls on rails like any cart. All block-carrying minecarts work the same; the Minecart with Chest page explains them.
It is made with the Crafting Table from Hopper and Minecart.
Hopper + Minecart → Minecart with Hopper
// Slots with several items cycle through every accepted option.
Put one Minecart with Hopper on each rail.
when powered, it throws the rider out of a Minecart, lights a Minecart with TNT and switches a Minecart with Hopper off (it stops pulling items until it rolls over an…
At the Crafting Table: 1 × Hopper and 1 × Minecart give 1 × Minecart with Hopper.
It is a minecart that carries a working block along the rails.
No: only one per inventory slot.