Java工具类之Arrays(一)

Arrays主要是针对数组进行操作的工具类,主要设置到数据的排序,二分查找,数组转换成List,数组复制,数组初始化,数组toString整体输出等等功能。

package three.day.util.my;

import java.util.Arrays; import java.util.List; public class Arraysts { /** * @param args */ public static void main(String[] args) { arraysTs(); arraysToString(); asList(); } private static void arraysTs() { int[]  a = {1,2,7,4,5,4,6,4,666,1,2}; int index = Arrays.binarySearch(a, 4); System.out.println(index); System.out.println("排序前:"); System.out.println(Arrays.toString(a)); Arrays.sort(a); System.out.println("排序后:"); System.out.println(Arrays.toString(a)); System.out.println("复制数组:"); System.out.println(Arrays.toString(Arrays.copyOf(a, a.length+10))); System.out.println("复制数组:"); System.out.println(Arrays.toString(Arrays.copyOfRange(a, 4, 20))); System.out.println("hashcode:"); System.out.println(Arrays.hashCode(a)); Arrays.fill(a, 1); System.out.println("填充后:"); System.out.println(Arrays.toString(a)); int[]  a1 = {1,2,7,4,5,4,6,4,666,1,2}; System.out.println("比较数据是否相等"); System.out.println(Arrays.equals(a, a)); } private static void arraysToString() { int[]  a = {1,2,3,4,5}; System.out.println(Arrays.toString(a)); } private static void asList() { int[]  a = {1,2,3,4,5}; List<int[]>  list = Arrays.asList(a); for(int it[] : list ){ for(int i : it ) System.out.println(i); } } }
相关文章
相关标签/搜索