不同类型的二维数组 [英] Two-dimensional array of different types

查看:143
本文介绍了不同类型的二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个二维数组,我想在其中存储数据库中的记录。所以让我们说第一个是类型为 int ,第二个是 String (这里我只描述一个记录所以基本上是db列的类型)。我该怎么做?数组是正确的数据结构吗?

I want to create a two-dimensional array in which I want to store records from the database. So lets say that the first is of type int and the second of type String (here I am describing just one record so basically types of db columns). How can I do it? Is an array the right data structure for that?

推荐答案

数组只能包含一种类型。如果该类型恰好是 Object ,那么它可以存储 Object 及其任何子类型,真的听起来像你想在这里完成的。

Arrays can only contain one type. If that type happens to be Object then it can store Object and any of its sub-types, but that doesn't really sound like what you're trying to accomplish here.

这听起来像你正在描述的是一个2D数组来存储数据库信息,每个元素在数组是其中一行中的列。这个不是一个记录数组,它是一列列数据。

It sounds like what you're describing is a 2D array to store database information, with each element in the array being a column in one of the rows. This isn't an array of records, it's an array of column data.

相反,只存储一维数组的记录,其中数组的每个元素都是对整个DB行的引用。

Instead, just store a one-dimensional array of records, where each element of the array is a reference to the entire DB row.

这篇关于不同类型的二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆