I am creating a method to extract values from a Set of clients , the values in question are the ID of all the clients present in the Set, the ID is obtained calling getClientID () .
My method:
public String[] extractIDsFromClientSet(Set<Client> clients) {
Client[] arrayClients = (Client[]) clients.toArray();
String[] clientIDs = new String[clients.size()];
for (int i = 0; i < arrayClients.length; i++) {
clientIDs[i] = arrayClients[i].getClientID();
}
return clientIDs;
}
By using my method I get the following exception:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lmodels.Client;
at view.userPanes.UserView.extractIDsFromClientSet(UserView.java:128)
at view.userPanes.UserView.setFieldData(UserView.java:82)
How do I correct my method?