数组操作工具类,专门用于操作数组元素
方法名:
public static String toString(类型[] a):将数组元素拼接为带有格式的字母
package com.bingyi.Object;
import java.util.Arrays;
public class ArraysDemo1 {
public static void main(String[] args) {
int[] arr1 = {11, 22, 33, 44, 55};
System.out.println(Arrays.toString(arr1));
}
}
public static boolean equals(类型[] a,类型[] b):比较两个数组内容是否相同
package com.bingyi.Object;
import java.util.Arrays;
public class ArraysDemo1 {
public static void main(String[] args) {
int[] arr1 = {11, 22, 33, 44, 55};
int[] arr2 = {11, 22, 33, 44, 55};
System.out.println(Arrays.equals(arr1, arr2));
}
}
public static int binarySearch(int [] a,int key):查找元素在数组中的索引(二分查找法)
package com.bingyi.Object;
import java.util.Arrays;
public class ArraysDemo1 {
public static void main(String[] args) {
int[] arr1 = {11, 22, 33, 44, 55};
System.out.println(Arrays.binarySearch(arr1, 33));
}
}
public static void sort(类型[] a) :对数组进行默认升降序
package com.bingyi.Object;
import java.util.Arrays;
public class ArraysDemo1 {
public static void main(String[] args) {
int[] arr1 = {55,44,43,44,66,88,0};
Arrays.sort(arr1);
System.out.println(Arrays.toString(arr1));
}
}