To add to Paul's list.....
Both the French and Spanish navies obtained a number of U-boats, especially Type VIICs, where they served as front line boats for quite a number of years.
One Type XXI, the U-2540, was raised after the war and put into service by the German Bundesmarine as a research vessel. She was renamed the Wilhelm Bauer
, after the German submarine pioneer. Upon retirement in the early 1980's, she became a museum ship and the original WW2 configuration was restored.
The Soviet Navy also obtained a number of all classes of U-boats, many of which served into the 50's. Take a look at a Foxtrot...and you'll see what is essentially a Type XXI U-boat.
Finally, the Norwegian Navy operated the U-995 (and a few others) for many years until returning her to Germany where she is open to the public as a museum ship as part of the Laboe Naval Memorial.