0

How do you pass multiple "hostnames" in following chunk of code where we are only passing one hostname? Is it possible?

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();
  }
} 
mmmmmm
  • 32,227
  • 27
  • 88
  • 117

1 Answers1

0

I don't see a proper API for this, why not just passing an array of Hosts and loop it?

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