int[] a = new int[10];
int a[] = new int[10];
int[] a = {1,2,3,4};
int[] a = new int[]{1,2,3,4};
public class ArrayTest
{
public static void main(String[] args)
{
int[] a = {1, 2, 3};
int[] b = {1, 2, 3};
System.out.println(a.equals(b));
}
}
ArrayEqualsTest.java
import java.util.Arrays;
public class ArrayEqualsTest
{
//Compare the contents of two int arrays
public static boolean isEquals(int[] a, int[] b)
{
if( a == null || b == null )
{
return false;
}
if(a.length != b.length)
{
return false;
}
for(int i = 0; i < a.length; ++i )
{
if(a[i] != b[i])
{
return false;
}
}
return true;
}
public static void main(String[] args)
{
int[] a = {1, 2, 3};
int[] b = {1, 2, 3};
System.out.println(isEquals(a,b));
System.out.println(Arrays.equals(a,b));
}
}
ArrayTest2.java
public class ArrayTest2
{
public static void main(String[] args)
{
Person[] p = new Person[3];
//未生成对象时,引用类型均为空
System.out.println(p[0]);
//生成对象之后,引用指向对象
p[0] = new Person(10);
p[1] = new Person(20);
p[2] = new Person(30);
for(int i = 0; i < p.length; i++)
{
System.out.println(p[i].age);
}
}
}
class Person
{
int age;
public Person(int age)
{
this.age = age;
}
}
Person[] p = new Person[]{new Person(10), new Person(20), new Person(30)};
public class ArrayTest3
{
public static void main(String[] args)
{
int[][] i = new int[2][3];
System.out.println("Is i an Object? "
+ (i instanceof Object));
System.out.println("Is i[0] an int[]? "
+ (i[0] instanceof int[]));
}
}
public class ArrayTest4
{
public static void main(String[] args)
{
//二维变长数组
int[][] a = new int[3][];
a[0] = new int[2];
a[1] = new int[3];
a[2] = new int[1];
//Error: 不能空缺第一维大小
//int[][] b = new int[][3];
}
}
public class ArrayTest5
{
public static void main(String[] args)
{
int[][] c = new int[][]{{1, 2, 3},{4},{5, 6, 7, 8}};
for(int i = 0; i < c.length; ++i)
{
for(int j = 0; j < c[i].length; ++j)
{
System.out.print(c[i][j]+" ");
}
System.out.println();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有