Java学习之路(18)----System类

前言

有关System类的所有函数的使用编程,使得更熟悉函数的使用。

时间

		//返回当前时间,毫秒为单位,返回值long
		System.out.println("------时间------");
		System.out.println(System.currentTimeMillis());
		//纳秒
		System.out.println(System.nanoTime());
		
		for(int i=0;i<10;i++){
			System.out.print(System.currentTimeMillis()+"   "+System.nanoTime());
			System.out.println();
		}
------时间------
1583041477818
147943121309200
1583041477818   147943122023300
1583041477818   147943123026500
1583041477818   147943123656100
1583041477818   147943124248400
1583041477818   147943124867000
1583041477818   147943125454600
1583041477818   147943126044400
1583041477818   147943126631500
1583041477818   147943127218500
1583041477818   147943127811400

输入

//System类的学习
import java.util.Scanner;
//import java.util.String;
public class SystemTest{
	public static void main(String[] args){
		
		//返回当前时间,毫秒为单位,返回值long
		System.out.println(System.currentTimeMillis());
		
		Scanner ss= new Scanner(System.in);
		System.out.println("请输入n");
		int n = ss.nextInt();
		System.out.println("请输入n个数");
		String[] sarray = new String[n];
		for(int i=0;i<n;i++){
			sarray[i]=ss.next();
		}
		System.out.println("输出");
		for(int i=0;i<n;i++){
			System.out.println(sarray[i]);
		}
		System.out.println("输入任意长度字符");
		while(ss.hasNext()){
			String s1 = ss.next();
			System.out.println(s1);
			if(s1.endsWith("<end>"))//终止
				break;
		}
		
		
		
	}
}
1583034036234
请输入n
3
请输入n个数
ghu
h
h
输出
ghu
h
h
输入任意长度字符
weui
weui
jvkl
jvkl
12mvk
12mvk
dffj<end>
dffj<end>

系统属性、环境

        System.out.println("------getenv当前系统环境的字符串映射图------");
		System.out.println(System.getenv());
		System.out.println("------getenv获取环境变量值------");
		System.out.println(System.getenv("JAVA_HOME"));
		//获取当前系统属性
		//System.out.println(System.getProperties());
		System.out.println("------getPropertity指定的系统属性------");
		System.out.println(System.getProperty("user.name"));

其他

//只是提醒虚拟机:希望进行一次垃圾回收
		System.gc();
		
		String s1= new String("huuu");
		String s2=new String("huuu");
		//字符串对象不同,identityHashCode不同
		System.out.println("------对象不同,identityHashCode------");
		System.out.println(System.identityHashCode(s1));
		System.out.println(System.identityHashCode(s2));
		//String重写HashCode,序列相同就相同
		System.out.println("------hashCode------");
		System.out.println(s1.hashCode());
		System.out.println(s2.hashCode());
		
		String s3 = "huu";
		String s4 = "huu";
		System.out.println("------对象相同,identityHashCode------");
		System.out.println(System.identityHashCode(s3));
		System.out.println(System.identityHashCode(s4));
		
		System.exit(0);
		//不会打印
		System.out.print("kkk");
------对象不同,identityHashCode------
1829164700
2018699554
------hashCode------
3214445
3214445
------对象相同,identityHashCode------
1311053135
1311053135
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值