According to the documentation you can prioritize IPv6 over IPv4 for hosts that have both A and AAAA DNS entries. This setting in turn sets the JAVA system property java.net.preferIPv6Addresses to true.
InetAddress.getByName(hostname) does return an IPv6 address for hosts with an A entry only. For hosts with both entries the IPv4 address is returned. The system property above does not have any effect in that case. Also refer to https://stackoverflow.com/a/11974740 which proposes to use InetAddress.getAllByName(hostname) or a 3rd party library.