The java.lang.System class provides a large number of static methods (no need to guide the package), which can obtain system-related information or system-level operations. In the API documentation of the System class, the commonly used methods are:
public static long currentTimeMillies(): returns the current time in milliseconds
/* public static long currentTimeMillies():返回以毫秒为单位的当前时间 用来程序的效率 验证for循环打印数字1-9999需要使用的时间 */ private static void demo01(){ long start = System.currentTimeMillis(); for (int i = 1; i < 10000; i++) { System.out.println(i); } long end = System.currentTimeMillis(); System.out.println(end-start); }
public static void arraycopy(Object str,int srcPos,Object dest,int destPos,int length): copy the specified data in the array to another array
/* public static void arraycopy(Object src,int srcPos,Object dest,int destPos,int length): 将数组中指定的数据拷贝到另一个数组中 参数:src--源数组 srcPos--源数组中的起始位置(索引) dest--目标数组 destPos--目标数据中的起始位置 length--要复制的数组元素的数量 练习:将src数组中的前3个元素,复制到dest数组的前3个位置上, 复制元素前:src数组元素[1,2,3,4,5],dest数组元素[6,7,8,9,10] 复制元素后:src数组元素[1,2,3,4,5],dest数组元素[1,2,3,9,10] */ private static void demo02(){ int[] src = {1,2,3,4,5}; int[] dest = {6,7,8,9,10}; System.arraycopy(src,0,dest,0,3); // 打印数组的方法 System.out.println(Arrays.toString(src)); System.out.println(Arrays.toString(dest)); }
Knowledge point recall: the tool class Arrays.toString(Object obj) converts the array into a string in the default format [xx,xx,xx]