java獲取數組長度


package cn.itcast.day05.demo03;

/*
如何獲取數組的長度,格式:
數組名稱.length

這將會得到一個int數字,代表數組的長度。

數組一旦創建,程序運行期間,長度不可改變。
*/
public class Demo03ArrayLength {

public static void main(String[] args) {
int[] arrayA = new int[3];

int[] arrayB = {10, 20, 30, 3, 5, 4, 6, 7, 8, 8, 65, 4, 44, 6, 10, 3, 5, 4, 6, 7, 8, 8, 65, 4};
int len = arrayB.length;
System.out.println("arrayB數組的長度是:" + len);
System.out.println("=============");

int[] arrayC = new int[3];
System.out.println(arrayC.length); // 3
arrayC = new int[5];
System.out.println(arrayC.length); // 5
}

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM