day05--数组的概述和3种定义格式

This commit is contained in:
2026-09-17 16:24:56 +08:00
parent 5e86d66221
commit 0a01ee2480
2 changed files with 52 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="17" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+41
View File
@@ -0,0 +1,41 @@
package com.inmind.array01;
/*
数组概念: 数组就是存储数据长度固定的容器,保证多个数据的数据类型要一致。
数组的3种定义格式
一.数组的动态初始化
数组存储的数据类型[] 数组名字 = new 数组存储的数据类型[长度];
数据类型[] 数组名 = new 数据类型[数组长度];
数组存储的数据类型:当前就是4类8种的基本数据类型,但是可以使用java中任意类型(引用类型)
[]:数组
数组名:就是标识符的一种,用来操作数组
new:java中的关键字,在堆内存中开辟空间
数组存储的数据类型:与前面的数据类型保持一致
[长度]:决定 数组的长度
二.数组的静态初始化
数据类型[] 数组名 = new 数据类型[]{值1,值2,值3...};
这种格式,没有直接给出数组的长度,但是根据传入的数据的数量,来确定
三.数组的静态初始化简写形式
数据类型[] 数组名 = {值1,值2,值3...};
这种格式,没有直接给出数组的长度,但是根据传入的数据的数量,来确定
*/
public class Demo01 {
public static void main(String[] args) {
//一.数组的动态初始化
//数组存储的数据类型[] 数组名字 = new 数组存储的数据类型[长度];
//请定义一个长度为3的存放整数int的数组
int[] arr1 = new int[3];
//二.数组的静态初始化
int[] arr2 = new int[]{1,2,3,4,5};
//三.数组的静态初始化简写形式
int[] arr3 = {1,2,3,4,5};
String[] arr4 = {"1","2","3"};
}
}