import java.util.Arrays; public class Test { public static void main(String[] args) { //数组的定义 //int[] a = new int[5]; //int a1[] = new int[3]; //int[] a2 = {2, 4, 6}; int[] a = new int[4]; boolean[] b = new boolean[4]; char[] c = new char[4]; System.out.println(Arrays.toString(a)); System.out.println(Arrays.toString(b)); System.out.println(Arrays.toString(c)); //二维数组定义 //int[][] aa = new int[4][]; //填充数组 Arrays.fill(a, 7); //填充一部分数组 Arrays.fill(a, 0, 2, 8); //复制数组 int[] newa = Arrays.copyOf(a, 3); //复制一部分数组 int[] newa1 = Arrays.copyOfRange(a, 0, 2); //数组排序 int[] aa = new int[]{24,54,33,55,43,53}; Arrays.sort(aa); p(aa); //数组的查询, 使用的是二分搜索法 int m = Arrays.binarySearch(aa, 54); int n = Arrays.binarySearch(aa, 0, 3, 54); System.out.println(n); } private static void p(int[] o) { System.out.println(Arrays.toString(o)); } }
1, 一维数组的定义, 初始化
2, 二维数组的定义
3, 填充数组
4, 数组排序
5, 数组的复制
6, 数组的范围复制
7, 数组查询
8, 数组的范围查询
时间: 2024-11-09 09:42:07