URLConnection explicitly establish a IPv4 connection only on localhost

When using a URLConnection is there any way to have it only connect via IPv4 when connecting to a server on localhost? My app needs to communicate with a server on the same machine that only offers IPv4.

On Windows 10 we have found that my app will first attempt to connect to the server using IPv6. It attempts this 5 times - timing out after 0.5 seconds each time. After the five attempts it tries to communicate via IPv4 which succeeds. Therefore it can take 2.5 to 3 seconds for the IPv4 server to respond to a command. A workaround is to enter the IPv4 IP address of the local machine and then all works fine.

Is there something wrong with just using ?