Here ,I am trying to convert map values into String array but i am getting
Error
ERROR/AndroidRuntime(23588): Caused by: java.lang.ClassCastException: [Ljava.lang.Object;
Code
Map<String,String> contactNumber = new HashMap<String,String>();
String results [] = (String[]) contactNumber.values().toArray();
Use Object#toString() . String string = map. toString();
One way to convert is to use the constructor of the ArrayList. In order to do this, we can use the keySet() method present in the HashMap. This method returns the set containing all the keys of the hashmap.
You should use the other toArray(T[] a) method.
String[] result = contactNumber.values().toArray(new String[0]);
You can't perform the cast like this. Instead, call the other toArray method:
String[] result = contactNumber.values().toArray(new String[0]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With