java - 数组是复合数据类型,但是如何呢?

Array is composite data type. A composite data type is one whose values are composed of component values (possibly values chosen from other data types.) Example of composite data type is array.

int a[ ] = {1,2,3,4,5};

在上面的示例中,据我所知,它是复合的,因为一个 array-of-int 值由从 int 类型中选择的一些元素值组成。使用复合数据类型,我们可以将多条相关数据作为单个数据进行管理。数组是使用以相同数据类型声明的多个值的概念。

请简单说明数组是复合数据类型。用例子解释这个说法?

最佳答案

A class defined with various primitive data types such as int, double etc;but i am using only one data type for array initialization that is int

考虑以下示例:

class Test {
    int a, b, c;
    Test() {
        a = 1 ; b = 2 ; c = 3;
    }
}

class Main {
    public static void main(String[] args) {
        Test object = new Test();
    }
}

根据您的定义,在这种情况下,即使类 Test 也将是原始数据类型,因为它只有 int 类型的值。然而,事实并非如此。

正如@Henry 所说,

The element types are irrelevant, important is only that there are several elements

所以基本上,我想说复合数据类型的更精确定义是:

The data types which are created by the user, which may consist of one or more primitive data types, created under a single declaration are called Composite data types.

根据该定义,数组也是复合数据类型。

https://stackoverflow.com/questions/63269364/

相关文章:

css - Angular ngx-bootstrap - 如何制作一个又大又宽的模态

reactjs - 我需要将浏览器路由器一分为二

perl - 为什么 local 在 STDERR 和 STDOUT 上不起作用?

php - 文件上传按钮在翻转卡上不起作用

postgresql - Postgres JSONB 检索非常慢

c# - 解析值行 1,位置 1 时遇到意外字符

docker - SMTP 未配置,请检查您的 grafana.ini 配置文件的 [smtp] 部

python - Pandas 在 Linux 中失败,在 Windows 中没有发生 - 缺少数据

postgresql - 使用 Aurora postgres serverless 在 AWS R

python-3.x - XGboost 目标 : Is there a way to do Mul