Although swimming was essential for survival for many species, over the centuries swimming became a favorite past time for humanoids. As well as swimming in natural water environments, swimming pools were built to allow people to swim more safely than could be possible in natural water.
Swimming as an organized activity goes back as far as 2500 B.C. in ancient Egypt. However, swimming pools did not became popular until the middle of the 19th century. 
By the 24th century holodeck technology was used to create swimming pools. Holodeck pools were safer than traditional pools in that if the computer detected someone drowning the water would disappear. (TNG novel Metamorphosis).
Swimming was a very popular past time for Humans, so much so that swimming pools were added into the facilities available aboard starships. Among many keen swimmers, are Deanna Troi and Yuri Kuznetsov. (TNG episode: "Conspiracy"; novel: Reunion)
In 2373, B'Elanna Torres was prepared for a swim as part of her workout regime in the holodeck, but on arrival, discovered that Tom Paris was already on the holodeck working on his holographic automobile, a '57 Chevy. (VOY short story: "Winds of Change")