If the child is hitting in order to get something, you will need to carefully examine the way you respond to the hitting. Using an ABA (Applied Behavioral Analysis) approach, you can use positive reinforcement for positive actions and negative reinforcement for negative actions in order to teach your child not to hit.
Make sure that if your child is hitting in order to get something, you do not reward the child with that object afterwards. In addition, if the child seems excited by your negative response - after all, your anger or frustration may make you look like a silly cartoon character in their eyes - tone down your response, and calmly remove the child from the situation and from any fun activity with a stern but brief comment. Make sure to give your child plenty of positive reinforcement, in the form of attention and excitement, when he or she is playing nicely and not hitting.
On the other hand, if your child is hitting for the sensory stimulation, try different activities to give your child the same physical feeling as hitting. This may mean letting your child bang on a drum, roll on the carpet, hit a pillow against a wall, or squeeze a ball of clay. These activities can both let out any excess energy and give your child the stimulation needed to avoid hitting others.