Android:在一个多维数组中存储 int 和 String 值
是否可以将不同的值存储到多维数组中,例如 int 和 String ?
String[][] mainArray= new String[2][2];
mainArray[0][0] = 1;
mainArray[0][1] = "Name1";
mainArray[1][0] = 2;
mainArray[1][1] = "Name2";
这显然不起作用,因为 1 和 2 不是字符串值
is it possible to store different values into a multidimensional array such as int's and String's?
String[][] mainArray= new String[2][2];
mainArray[0][0] = 1;
mainArray[0][1] = "Name1";
mainArray[1][0] = 2;
mainArray[1][1] = "Name2";
this obviously doesn't work because 1 and 2 are not String values
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,你可以存储
试试这个
yes you can store
try this
您可以创建一个
Object
数组,并保存Integer
,它是基元int
的装箱。You can create an
Object
array, and saveInteger
s, which is the boxing of the primitiveint
.这是解决方案
,但是在访问此数组时,您还应该仅使用 Object 来执行此操作。否则可能会出现 ClassCastException。
Here is the solution
But while accessing this array you should also do this using Object only.Else there may be ClassCastException.