A needle sinks in water because the weight of water displaced by it is less than the weight of needle .AND an iron ship is shaped that it can displace a large volume of water.The weight of the water displaced by the immersed portion o the ship is equal to the weight of the ship hence it can float. According to the law of floatation a body floats in a liquid when the weight of the whole body is equal to the weight of the liquid displaced by the immersed portion of the body.
In short, we can say that the shape of the ship makes its overall density less than that of water and hence the ship floats.