包装类 Math Data System

来源:互联网 发布:cherry键盘 mac 编辑:程序博客网 时间:2024/05/18 02:40

常用类
包装类:
属性构造 方法:1.转成int、转成integer、转成字符串2.进制转换
Integer:integer()integer(String s) ;max_values min_values size type
integer.parseInt() Integer.toString() Integer.valuOf()
integer.toBinaryString integer.toOctalStringinteger.toHexString
character:
是否字符、是否数字、是否大小写、大小写转换
charValue():把character转换成char charAt() isDigital() isLowCse()
isLetter() isUpperCase() toLowCase() toUpperCase()
String:
charAt() lengh() startWith() endWith() indexOf()concat() lastIndexOf()
contains() equals() subString() split()trim() replace matches()
getBytes() toLowerCase() valueOf()
注意:split()返回值为String数组,数组长度由切割符决定。例如String str=”1,2,3!4,5,6,0!7,8,9”;按照“!”切割后的长度为3
[1,2,3, 4,5,6, 0, 7,8,9]

for (int i = 0; i <firstArr.length; i++) {中再次按照“,“切割后的结果如下:[1, 2, 3] [4, 5, 6, 0] [7, 8, 9]

StringBuffer:字符串缓冲区
构造:stringBuufer():初始16个字符stringBuufer(“abc”)
注意:超过大小缓冲会自动增加
方法:insert() delete() reverse() append()indexof() +string方法
StringBuffer与StringBuilder的区别
StringBuffer支持多线程,多线程操作是同步操作。
StringBulider是线程不安全的。
Math
Abs() floor() ceil() round() random() pow(3,2)=9sqr(27,3)=3 max min
Date:
构造:Date d=new Date();//系统当前时间
Date d=new Date(long date); 参数为毫秒数
date=System.currentTimeMillis():获取毫秒(1970)
方法:已被calendar替代
Calendar:抽象类
方法:
Calendar cal=Calendar.getInstance();//获取实例
Cal.get(Calendar.DAY_OF_MONTH)://获取年月日,时分秒等
SimpleDateFormat:格式化日期
SimpleDateFormat sdf = newSimpleDateFormat(
“yyy-MM-dd hh:mm:ss”);
Datedate = new Date();
Strings = sdf.format(date);
System.out.println(s);
使用步骤:
1. 创建simpleDateFormat 对象。同时指定日期格式。
2. 获取data对象(系统时间)
3. 使用第1步的格式对象的format()
4. 使用格式化后的字符串结果
System
字段:
In(输入流)、out(输出流):黑色输出、err(标准错误流):控制台红色输出
方法:
1. arraycopy
2. exit(int status):终止当前正在运行的 Java 虚拟机.
Staus: 非 0 的状态码表示异常终止。0:保存并退出。
3. currentTimeMillis()
Runtime:
Runtimert=Runtime.getRuntime();//获取实例
方法:
1. exit(int status):通过启动虚拟机的关闭序列,终止当前正在运行的Java 虚拟机。类似于word关闭弹窗警告。
2.freeMemory();返回jvm 中的剩余容量。字节为单位
3.maxMemory():返回 Java 虚拟机试图使用的最大内存量
4.totalMemory():返回 Java 虚拟机中的内存总量
Random类构造函数:
1. Random():如果想获取随机数 nextInt(100)
Random ad=new Random();
System.out.println(ad.nextInt(100));
100以内随机数
5. Random(long seed):以特定种子生成随机数,种子不变随机数不变。
Random ad=new Random(30);
System.out.println(ad.nextInt(100));

集合:collection
定义:类似数组 进行了一些功能扩展 允许存放不同数据类型,但是通常会加以控制,不让集合随便存放数据类型。–》泛型
Collection:根接口 子接口:
常用方法:
添加:add() addAll()
删除:clean():清空 remove(indexx):单个 remove(String name)
获取大小:size() 是否相等:equals()集合转成数组:toArray()
判断包含:contains 迭代器:iterator
泛型:只能是引用类型
补:在for循环中如果想在不是第一次时进行某种操作,可以从后往前进行
ConcurrentModificationException:并发修改异常
Arraylist中的set()理解:用object替换指定位置并返回原先的值
ConcurrentModificationException:并发修改异常

0 0