“新双”的目的

时间:2015-08-13 04:23:56

标签: arrays double

new double[5]

"CODE","BRAND","DESIGNER","SIZE","TYPE","GENDER","SET","DESCRIPTION","IMAGE","COST","WEIGHT","MSRP","UPC" "M-1001","212","Caroline Her","1.7 oz","EDT Spray","Men","","text.","http://www.domain.com/products/Men/Final/M-1001large.jpg","31.08","1","57.00","8411061341704" "M-1003","1881","Nino Cer","1.7 oz","EDT Spray","Men","","text.","http://www.domain.com/products/Men/Final/M-1003large.jpg","24.13","1","36.00","688575003642" "M-1004","1881","Nino Cer","3.4 oz","EDT Spray","Men",""," text.","http://www.domain.com/products/Men/Final/M-1004large.jpg","37.51","1","50.00","688575003659" 在此声明中做了什么?

3 个答案:

答案 0 :(得分:0)

它不只是new double,它是new double[5]创建一个最多5个双打的数组

正如oracle doc所解释的那样(https://docs.oracle.com/javase/tutorial/java/nutsandbolts/arrays.html

// declares an array of integers
int[] anArray;

// allocates memory for 10 integers
anArray = new int[10];

// initialize first element
anArray[0] = 100;
// initialize second element
anArray[1] = 200;

所以double empHousingAllow[] = new double[5];为五个双打的数组分配内存

答案 1 :(得分:0)

Java中的new关键字用于创建对象。在这种情况下,正在创建的对象是一个包含五个双精度数组的数组。

您可能需要查看this question,它更详细地描述了数组的声明。

答案 2 :(得分:0)

实际上,当您定义数组时,概念需要大小,以后您无法更改大小。

您无法直接将值分配给内存块,如

double d[5];
d[0] = 10.05;

您需要创建具有特定类型的内存块。 这就是你需要以这种方式定义数组的原因。

double d[] = new double[5]

double d[5];
d[0] = new double like that.

然后你可以将值添加到该块。