数组的两种写法:定义与传参
public class ArrayTest{ public void print(String... mes){ for(String str:mes){ System.out.println(str); } } public void print1(String[] mes){ for(String str:mes){ System.out.println(str); } } public static void main(String[] args){ String[] arr={"aa","bb","cc"}; ArrayTest at=new ArrayTest(); at.print(arr); String[] arr1=new String[3]; arr1[0]="dd"; arr1[1]="ee"; arr1[2]="ff"; at.print1(arr1); } }
运行结果:
import java.util.Arrays; public class javaArrays{ public static void main(String[] args){ int[] a1=new int[]{1,2,3,4,5}; int[] a2=new int[]{1,2,3,4,5}; System.out.println(Arrays.equals(a1,a2)); int[] b1=Arrays.copyOf(a1,8); System.out.println(Arrays.toString(b1)); Arrays.fill(b1,2,6,9); System.out.println(Arrays.toString(b1)); Arrays.sort(b1); System.out.println(Arrays.toString(b1)); } }
热心技术,并兼吃喝,偶谈风月,不言国事.