gpt4 book ai didi

java - 如何在 "hostnames"方法中传递 "InetAddress"数组而不是传递一个主机名

转载 作者:行者123 更新时间:2023-12-01 14:50:52 24 4
gpt4 key购买 nike

如何在下面的代码块中传递多个“主机名”,而我们只传递一个主机名?可能吗?

private static void run() {

String host = "www.google.com";
try {
inetAddress = InetAddress.getAllByName(host);
String all = "";
for (int i = 0; i < inetAddress.length; i++) {
all = all + String.valueOf(i) + " : " + inetAddress[i].toString() + "\n";
Log.d("IPADDR", "IP Address : " + all);
prefs.sethostIPaddress(context, all); //Setting HostIP Address in Preference File
}
}
catch (UnknownHostException e) {
e.printStackTrace();
}
}

最佳答案

我没有看到合适的 API,为什么不直接传递一个主机数组并循环它呢?

String[] hosts = {"www.google.com", "www.pippo.com", "...."};
for(String host : hosts){
// Do your thing
}

关于java - 如何在 "hostnames"方法中传递 "InetAddress"数组而不是传递一个主机名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14872277/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com