儲存類的倉庫---JAVA常用類庫

2020-08-11 23:09:57

API概念

系統提供的已實現的標準類集合

基本數據型別的包裝類

基本數據型別 基本數據型別的包裝類
int Integer
char Character
float Float
double Double
byte Byte
long Long
short Short
boolean Boolean
public class demo {
	
	public static void main(String []args)
	{
	String a="123";
	int i=Integer.parseInt(a);//基本數據型別的包裝類
	i++;
	System.out.println(i);
    }
}

裝箱和拆箱

裝箱:把基本型別用它們相對應得參照型別包裝起來
拆箱:將參照型別的物件重新簡化爲值型別的數據

public class demo {
	
	public static void main(String []args)
	{
	Integer x=new Integer(10);//裝箱
	int temp =x.intValue();   //拆箱
	System.out.println(temp);
    }
}

基本數據型別與字串的轉換

使用包裝類的最大操作特點:可以將字串變成指定數據型別。

public static int parseInt(String x);
public static double parsedouble(String x);
public static Boolean parseBoolean(String x);
public class demo {
	
	public static void main(String []args)
	{
	String a="123.4";
	String b="123";
	String c="true";
	double x1=Double.parseDouble(a);
	int x2=Integer.parseInt(b);
	boolean x3=Boolean.parseBoolean(c);
	System.out.println(x1+"*"+"2="+x1*2);
	System.out.println(x2+"*"+"2="+x2*2);
	System.out.println(x3);
    }
}

在这里插入图片描述

基本型別變成字串

String.valueof();

System類和Runtime類

System類

1.JAVA不支援全域性方法和變數,JAVA設計者將一些系統相關的重要方法和變數收集到一個統一的類中,這就是System類。
2.System類中的所有成員都是靜態的,所以可以直接用類名做字首

exit方法

提前終止虛擬機器的執行
1.如果是發生異常情況而想終止虛擬機器執行,傳遞一個非零值作爲參數
2.如果是正常操作下終止虛擬機器執行,傳遞零值作爲參數

currenttimemillis方法

getproperties方法

獲取當前虛擬機器的環境變數
每一個屬性都是變數與值以成對的形式出現的

public class demo {
	
	public static void main(String []args)
	{
	Properties p=System.getProperties();//獲得當前虛擬機器的環境變數
	Enumeration<?> e=p.propertyNames();//獲得環境屬性中的所有變數
	while(e.hasMoreElements())//回圈列印所有環境屬性的變數和值
	{
		String key=(String)e.nextElement();
		System.out.println(key+"="+p.getProperty(key));
	}
    }
}

Runtime類

runtime表示的是執行時在每一個JVM進程之中都會存在唯一的一個Runtime類的範例化物件。

public class demo {
	
	public static void main(String []args)
	{
	Runtime run=Runtime.getRuntime();
	System.out.println(run.freeMemory());//空閒記憶體數
	System.out.println(run.totalMemory());//總共可用記憶體數
	}
}

日期操作類

正則表達式

正則標記