System类
-System类常见的方法和案例
- exit退出当前程序
- arraycopy:复制数组元素,比较适合底层调用,一般用Arrays.copyOf完成复制数组。
- currentTimeMillens:返回当前时间距离1970-1-1的毫秒数
- gc:运行垃圾回收机制System.gc();
exit()
public class System_ {
public static void main(String[] args) {
System.out.println("hello");
// System.exit(0); 表示程序退出
// 0表示一个(正常)状态
System.exit(0);
System.out.println("java");
}
}
System.arraycopy()
public class System_ {
public static void main(String[] args) {
int[] arr={1,2,3};
int[] arr2=new int[3];
/*
Params:
src – the source array. // 源数组
srcPos – starting position in the source array. // 从源数组的指定索引位置
dest – the destination array. // 拷贝到的目标数组的名称
destPos – starting position in the destination data. // 指定拷贝到目标数组的指定位置
length – the number of array elements to be copied. // 从源数组拷贝数据个数
*/
System.arraycopy(arr,0,arr2,0,3);
System.out.println("复制后的新数组:"+ Arrays.toString(arr2));
}
}
本文作者:Dr丶云幕
本文链接:https://www.cnblogs.com/vayenge/p/18198924
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步