Q: how to convert a set into an array of Strings?
in
Programming Questions
•
3 years ago
Greetings all,
I have a HashMap that uses a String as they key, and a composite Object as value. I have been able to convert the keys used in the hashmap into an array of Strings with a two step process:
Is there anyway to do away with the temporary Object[] array and the for-loop to convert the objects to strings?
Thanks!
I have a HashMap that uses a String as they key, and a composite Object as value. I have been able to convert the keys used in the hashmap into an array of Strings with a two step process:
- HashMap words;
- String[] keyWords;
- Object[] temp;
- temp = words.keySet().toArray();
- keyWords = new String[temp.length];
- for(int i=0; i<temp.length; i++) {
- keyWords[i] = temp[i].toString();
- }
Is there anyway to do away with the temporary Object[] array and the for-loop to convert the objects to strings?
Thanks!
1