In most cases, yes
An elimination diet is an effective way of avoiding allergic reactions to foods.
However, your physician should ascertain that you are allergic. A positive skin or blood test for allergy is not enough. You also need to have a suffered a reaction that correlates with that test (for instance developing hives
when you eat peanuts).