十三.储存类的仓库---JAVA常用类库

API概念

系统提供的已实现的标准类集合

基本数据类型的包装类

基本数据类型基本数据类型的包装类
intInteger
charCharacter
floatFloat
doubleDouble
byteByte
longLong
shortShort
booleanBoolean
public class demo {
	
	public static void main(String []args)
	{
	String a="123";
	int i=Integer.parseInt(a);//基本数据类型的包装类
	i++;
	System.out.println(i);
    }
}
Integer类

Integer的三种创建方法

		Integer a=new Integer(200);
		Integer b=Integer.valueOf(200);
		Integer c=200;
		System.out.println(a+"\t"+b+"\t"+c+"\t");

装箱和拆箱

装箱:把基本类型用它们相对应得引用类型包装起来
拆箱:将引用类型的对象重新简化为值类型的数据

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());//总共可用内存数
	}
}

日期操作类

正则表达式

正则的引出

public class demo {


	public static boolean isnumber(String str)
	{
		char []data=str.toCharArray();//将字符串转换为char数组!!!!
		for(int i=0;i<data.length;i++)
		{
			if(data[i]<'0'||data[i]>'9')
			{
				return false;
			}
		}
		return true;
	}
	
	public static void main(String []args)
	{
	if(isnumber("123"))
	{
		System.out.println("字符串由数字构成");
	}
	else
		{
		System.out.println("字符串不由数字构成");
		
		}
	}
}

正则标记

字符

x:表示是一个指定的一位字符
\:表示一位字符“\”

字符范围

在指定的字符范围中选择一位
[abc]:表示可以是abc的任何一位
[^abc]:表示不是abc中的任意一位
[a-zA-Z]:表示是任意一位字母(可大写,小写)
[0-9]:表示任意一位数字

简洁表达式

. :表示任何一位字符
\d :表示任何一个数字,等价于[0-9]
\D:表示任何一个非数字,等价于[^0-9]
\s:表示一位空格
\S:表示一位非空格
\w:表示一位字母,数字,_ ,
等价于[a-zA-Z0-9_]
\W:表示一位非字母,数字,_ ,
等价于 [ ^ a-zA-Z0-9 _ ]

边界匹配

JAVA用不上

数量表示(每个符号表示多位)

正则?:正则出现0,1次
正则+:正则出现1,多次
正则*:正则出现0,1,多次
正则{n}:正则出现n次
正则{n,}:正则出现n次以上
正则{n,m}:出现n~m次

逻辑操作

正则1正则2:正则1跟在正则2之后
正则1|正则2:表示或
(正则) :表示按一组使用

/**
正则标记的使用
*/
 public static void main(String []args)
	{
	if("123".matches("\\d+"))
	{
		System.out.println("字符串由数字构成");
	}
	else
		{
		System.out.println("字符串不由数字构成");
		
		}
/**
字符串的替换
*/
public static void main(String []args)
	{
	String str="ab35436dr2443dv45436";
	String regex="\\d+";//等价于regex=“[0-9]+”
	System.out.println(str.replaceAll(regex, ""));
	}

在这里插入图片描述

/**
验证邮箱格式
*/
public static void main(String []args)
	{
	String str="abc@163.com";
	String regex="\\w+@\\w+.\\w+";
	System.out.println(str.matches(regex));
	}

Math类和Random类

Math类提供了一些简单的数学运算

random.nextInt(100)//产生一个0-100之间的整数

大数字操作类

大型整数操作类biginteger

/**
	 * 大型整数操作
	 * @param args
	 */
	public static void main(String []args)
	{
	BigInteger big1=new BigInteger("99999999999999999");
	BigInteger big2=new BigInteger("888888888888888888");
	System.out.println(big1.add(big2));   //加法操作
	System.out.println(big1.subtract(big2));   //减法操作
	System.out.println(big1.multiply(big2));   //乘法操作
	System.out.println(big1.divide(big2));//除法操作
	BigInteger []result =big1.divideAndRemainder(big2);//除法操作,保存商和余数
	System.out.println("商:"+result[0]+",余数:"+result[1]);
	}

在这里插入图片描述

大型浮点数操作类BigDecimal

和Biginteger类的使用方法相似

public static void main(String[] args)
	{
	BigDecimal bigA=new BigDecimal("9999999999.99999");
	BigDecimal bigB=new BigDecimal("1111111111.11111");
	System.out.println("加法:"+bigA.add(bigB));
	System.out.println("减法:"+bigB.subtract(bigA));
	System.out.println("乘法:"+bigA.multiply(bigB));
	System.out.println("除法:"+bigA.divide(bigB));
	System.out.println("双精度:"+bigA.doubleValue());
	System.out.println("单精度"+bigA.floatValue());
	System.out.println("长整型"+bigA.longValue());
	System.out.println("整形"+bigA.intValue());
	String str=bigA.toString();
	System.out.println(str+"1");
	System.out.println(str+1);
	
    }

Boolean类

public class demo {
	public static void main(String[] args)
	{
	Boolean boo1,boo2;
	boo1=Boolean.valueOf(true);
	boo2=Boolean.valueOf(false);
    }

Byte类

public static void main(String[] args)
	{
	byte b=127;
	Byte b1=Byte.valueOf("127");
	Byte b2=new Byte(b);
	Byte b3=127;
	int x1=b1.intValue();
	int x2=b2.intValue();
	int x3=b3.intValue();
	System.out.println("b1:"+x1+"b2:"+x2+"b3:"+x3);
	String str1=Byte.toString(b);
	String str2=Byte.toString(b1);
	String str3=b1.toString();
	System.out.println("str1:"+str1+"str2:"+str2+"str3:"+str3);
	byte b4=Byte.parseByte(str1);
	System.out.println("b4:"+b4);
    }

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值