Can CH3COOH be written as C2H4O2? I was reading a chapter on acids and bases .It said something about acetic acid.And then I thought whether I could write CH3COOH as C2H4O2? please explain your answer.

Thanks!!
$\ce{C2H4O2}$ is the molecular formula of acetic acid. As such, it's a correct method to write the molecule. However, you should note that, as Ivan Neretin mentioned, molecular formulae are not necessarily unique for a given molecule.