Java_数组操作_基本定义及细节

来源:互联网 发布:mac maven 仓库地址 编辑:程序博客网 时间:2024/06/05 00:53
package test;public class test {public static void main(String[] args) {// 声明数组并未初始化,大多数程序员使用此方式声明,因为将元素类型与变量名分开了int[] a;// 声明数组并未初始化,不推荐,很少使用int b[];// 创建数组对象并同时赋予初始值int[] smallPrimes = { 2, 3, 5, 7, 13 };/* * 以下为不创建新变量的情况下重新初始化一个数组 * 等同于: * int[] anonymous = { 17, 33, 22, 6, 84 }; * smallPrimes = anonymous; */smallPrimes = new int[] { 17, 33, 22, 6, 84 };// Java允许数组的长度为0,在编写一个结果为数组的方法时,如果碰巧结果为空,那么这种语法形式就显得非常有用。注意:数组长度为0,与null不同int[] c = new int[0];}}

0 0