转换映射值变为字符串数组数组、字符串

2023-09-05 05:04:17 作者:沿海奔跑的少年。

在这里,我想映射值转换成字符串数组,但我得到

错误

  ERROR / AndroidRuntime(23588):java.lang.ClassCastException:产生的原因[Ljava.lang.Object;
 

code

 地图<字符串,字符串> contactNumber =新的HashMap<字符串,字符串>();

。字符串结果[] =(字符串[])contactNumber.values​​()的toArray();
 

解决方案 labview怎么把字符串转换为数组 labview将字符串转换为数组的方法

您应该使用其他toArray(T[]一)方法。

 的String []的结果= contactNumber.values​​()的toArray(新的String [0])。
 

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();

解决方案

You should use the other toArray(T[] a) method.

String[] result = contactNumber.values().toArray(new String[0]);