How to Call method with arguments coming from a hashset?

  static public void Configure( Activity activity,String client_options,
        String app_id, String... zone_ids )

I have this hashset that contains up to 500 elements.

How can I call Configure() with each element of the hashset as a argument fulfilling the zone_ids parameter?

Jon Skeet
people
quotationmark

Unfortunately, you'd need to convert the set to an array - it's easy to do, but quite inefficient:

Configure(activity, options, appId, zoneIdSet.toArray(new String[0]));

The new String[0] could be replaced by new String[zoneIdSet.size()] to be slightly more efficient. You have to pass in an array to get around the type erasure of Java, so that it can build an array of the correct type.

You've said you have no control over the method - if you could, it would be cleaner to have two overloads:

public void configure(Activity activity, String clientOptions,
    String appId, Iterable<String> zoneIds) {
    // Actual work here
}

// Convenience overload
public void configure(Activity activity, String clientOptions,
    String appId, Iterable<String> zoneIds) {
    configure(activity, clientOptions, appId, Lists.asList(zoneIds));
}

Then you'd just "wrap" the array in a list to make it an Iterable<String>.

people

See more on this question at Stackoverflow