
本文共 6395 字,大约阅读时间需要 21 分钟。
������������
���������
- ���������������������������������������������
- ������,������������������������������������������������������������������������������������������������������
���������������
- ���������������������������������������������������������������������������������������������
- ������������������������������������������������������������������
- ������������������������������������������������������������������������������������
- ������������������������������������������������������������������������������������������������������������������������������������������������������Java������������������������������������������������������������������������������������������������������������������������������������
������������������
���������
/* ��������������������������������������� */elementType[] arrayVarName/* ������������������������������������ */elementType arrayVarName[]
���������
- ������������������������������������������������������������������������������������������
- Java������������������������������������������������������������'������������'���������������������������'���������'������
���������
- ���������������������������������'������������'������������������������������������������������������������
- ������������������������������������������'���������'���������������������C/C++���������������������������������C/C++������������������Java���������������������������������������
- ������������������������������������������������������������������������������������
- ������������������������������������������������������������������������������������������������������JVM���������������������������������������������
���������
/* ������������ */int[] intArr1;/* ��������������� */int intArr2[];
������������������
���������
������������������
new elementType[arrayLength]
������������������
{firstElementValue, secondElementValue, thirdElementValue...}
���������
- ������������������������������������������������������������������
- ���������������������������������������������������������������������������������������������������������������������������������������������������������������
- ���������������������������������������������������������������������������������������������������������������
- ������������������������������������������������������������������������������������������������������������������������������������������
���������
���������������������������������������������������������������������������������������������������������������������������������������
���������������������������������������������
���������
/* ��������������� */new int[5];/* ��������������� */{1, 2, 3, 4, 5};
������������������
���������������������
���������
/* ������������������������������������ */elementType[] arrayVarName = new elementType[arrayLength];/* ������������������������������������ */elementType[] arrayVarName = {firstElementValue, secondElementValue, thirdElementValue...};
���������
- ������������������������������������������������������������������������������������������������������������������������������
���������
/* ������������������������������������ */int[] intArr1 = new int[5];/* ������������������������������������ */int[] intArr2 = {1, 2, 3, 4, 5};
������������������
���������
arrayObject.length
���������
- ������������������������������������������������������������������������
- ������������������������������������������������������������������������������������������������������������
���������
int[] intArr = {1, 2, 3, 4, 5};System.out.println(intArr.length);//5
������������������
���������
arrayObject[elementIndex]
���������
- ������������������������������������������������������
- ���������������'0'������������������������������������������������������������������������������������������������0 ~ arrayObject.length-1
���������
- ���������������������������������������������������������������������������������������������������������������������������������ArrayIndexOutOfBoundsException���������������������������������
���������
int[] intArr = {1, 2, 3, 4, 5};System.out.println(intArr[1]);//2
������������������������������
���������
'for'������
for (int i = 0; i < arrayObject.length; i++) { /* ������'arrayObject[i]'������������������������ */}
'foreach'������
for (elementType elementVarName : arrayObject) { /* ������'elementVarName'������������������������ */}
���������
���������������������������������������������������������������������������������������������������������������'for'������������'foreach'������������������'for'������������
'foreach'������������������������������������������������������
���������
/* ������������������������������������������1 2 3 4 5 1 2 3 4 5 */public static void main(String[] args) { int[] intArr = {1, 2, 3, 4, 5}; /* for������������������ */ for (int i = 0; i < intArr.length; i++) { System.out.println(intArr[i]); } /* foreach������������������ */ for (int element : intArr) { System.out.println(element); }}
������������������
���������
������
innerElementType[][] arrayVarName
������
/* ��������������������������� */new elementType[outerArrayLength][innerArrayLength]/* ��������������������������� */{{innerFirstElementValue, innerSecondElementValue, innerThirdElementValue...},{innerFirstElementValue, innerSecondElementValue, innerThirdElementValue...},{innerFirstElementValue, innerSecondElementValue, innerThirdElementValue...}...}
������������
/* ������������������������ */arrayObject.length/* ��������������������������������������������������� */arrayObject[outerIndex].length
������������
/* ��������������������������������������������������������������� */arrayObject[outerIndex]/* ��������������������������������������������������������������������������������� */arrayObject[outerIndex][innerIndex]
���������
- ���������������������������������������������������������������������
- ������������������������������������������������������������������������������������������������������������������������������������������������
���������
/* ������������������������������������������1 2 2 3 3 4 4 5 5 6 */public static void main(String[] args) { int[][] arrayObject = {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}}; /* ������foreach������������������������ */ for (int[] innerArr : arrayObject) { for (int innerElement : innerArr) { System.out.println(innerElement); } }}
发表评论
最新留言
关于作者
