Arrays常用方法:
package com.java.base3.Practice; import java.util.Arrays; public class ArraysTest { public static void main(String[] args) { int[] arr = {1, 2, 3, 4}; int[] arr1 = {1, 3, 2, 4}; // Arrays.equals 对比两数是否相等 boolean isEquals = Arrays.equals(arr, arr1); System.out.println(isEquals); // Arrays.toString 输出数组信息 System.out.println(Arrays.toString(arr1)); // 将指定的值填充到数组之中 Arrays.fill(arr, 99); System.out.println(Arrays.toString(arr)); // 快速排序 Arrays.sort(arr1); System.out.println(Arrays.toString(arr1)); //索引位置查询 int[] array2 = {10, 30, 50, 100, 256, 777, 787, 666}; int index = Arrays.binarySearch(array2, 90); if (index >= 0) { System.out.println("50的索引位置是:" + index); } else if (index < 0) { System.out.println("非常抱歉,索引不在此位置以内"); } } }
原文地址:https://www.cnblogs.com/lizhen1412/p/11184000.html
时间: 2024-10-15 21:20:10