ToString
定义一个数组
public static void main(String[] args) {
int[] arr = {8,1,2,3,4,5,6,7};
System.out.println(arr);
}
直接打印输出的结果位该数组的内存地址 想要输出数组里的内容可以通过for循环进行遍历输出
public static void main(String[] args) {
int[] arr = {8,1,2,3,4,5,6,7};
System.out.println(arr);
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+",");
}
}
*/
public static void main(String[] args) {
int[] arr = {8,1,2,3,4,5,6,7};
System.out.println(Arrays.toString(arr));
}
Arrays.sort(对数组进行排序)
public static void main(String[] args) {
int[] arr = {8,1,2,3,4,5,6,7};
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
}
ArraysbinarySearch(对数组进行二分查找)
查询下标位6的值
public static void main(String[] args) {
int[] arr = {8,1,2,3,4,5,6,7};
Arrays.sort(arr);
System.out.println(Arrays.toString(arr));
System.out.println(Arrays.binarySearch(arr,6));
}
CopyOf(对数组进行扩容)
将数组扩容到15
public static void main(String[] args) {
int[] arr = {8,1,2,3,4,5,6,7};
System.out.println(arr.length);
arr= Arrays.copyOf(arr, 15);
System.out.println(arr.length);
}
|