一 Object类
1.1 toString()
主要用途:重写这个方法可以自定义对象输出格式(默认格式 :类名 + @ +哈希码值)
1.2 equals()
主要用途 : 判断两个对象是否相同,默认的是比较两个对象的内存地址,一般重写equals方法的时候也会重写hasCode方法
1.3 hasCode()
主要用途 : 获取类的哈希码值,哈希码值相当于是类的内存地址
二 String类和StringBuffer
2.1 String类
2.1.1 字节数组构建字符串
String(byte[] bytes)
2.1.2 字符数组构建字符串
String(char[] value)
2.1.3 获取的方法
int length() //获取字符串长度
char charAt(int index) //获取特定位置的字符
int indexOf(String str) //获取字符的位置
2.1.4 判断方法
boolean endsWith(String str) //是否以指定的字符结尾
boolean isEmpty() //是否为空
boolean contains(Char Sequences) //是否包含指定的内容
boolean equalsIgnoreCase(String anotherString)//忽略大小写是否相等
2.1.5 转换方法
char[] toCharArray() //将字符串转换为字符数组
byte[] getBytes() //将字符串转换为字节数组
2.1.6 其他方法
String[] split(String regex) //分割字符串的方法
String substring(int beginIndex) //截取字符串的方法
String toUpperCase() //转大写
String trim() //去除字符串首尾空格
2.2 StringBuffer 与 StringBuilder
StringBuffer和StringBuilder主要用于对字符串频繁增删改查的情况
2.2.1 添加的方法
append() //添加字符
insert(int offset,b) //插入索引值,插入的内容
2.2.2 删除的方法
delete(int start, int end) //根据指定的开始与结束的索引值删除对应的内容
deleteCharAt(int index) //根据指定的索引删除一个字符
2.2.3 修改
replace(int start, int end , String str) //把指定索引值的字符替换为指定的字符
reverse() // 反转字符串
2.2.4 查看
indexOf(String str, int fromIdnex) // 查找指定的字符串第一次出现的索引值,并且指定开始查找的位置
2.2.5 StringBuffer 与 StringBuilder(常用) 的相同与不同
相同:
1.两个类都是字符串缓冲类
2.两个类的方法都一样
不同:
1.StringBuffer是线程安全的,操作效率低,StringBuffer是线程非安全的,操作效率高
2.StringBuffer是jdk1.0出现的, StringBuilder 是jdk1.5的时候出现的.
三 System 和 RunTime类
3.1 System类
3.1.1 System常用方法
currentTimeMillis() //获取当前系统时间
exit(int status) //退出jvm
gc() //建议jvm启动垃圾回收机制
getProperties();//获取系统的所有属性
3.2 RunTime类
3.2.1 RunTime常用方法
getRuntime(); // 返回当前应用程序的运行环境对象
exec(String command) //根据指定的路径执行对应的可执行文件
freeMemory() //获取jvm的空闲内存,以字节为单位
totalMemory() //返回jvm的内存总量
四 日期类
4.1 Calendar类
Calendar calendar = getInstance(); //获取当前的系统时间类
calendar.get(Calendar.YEAR)//获取年份
calendar.get(Calendar.MONTH)+1 //获取月份
calendar.get(Calendar.HOUR_OF_DAY) //获取小时,24小时制
4.2 SimpleDateFormat类(常用)
4.2.1 把日期转换成指定格式的字符串
Date date = new Date();//获取当前的系统时间
SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");//设置格式化模式
String time = simpleFormat.format(date);
4.2.2 把字符串转换为对应的日期
SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
String birthday = "2000年12月26日 11:29:08";
Date date = simpleFormat.parse(birthday);//注意:指定的字符串格式必须要与SimpleDateFormat模式一至
五 Math类
5.1常用的方法
abs(double a) //获取绝对值 Math.abs(-3)
ceil(double a) //向上取整
floor(double a) //向下取整
round(float a) //四舍五入
5.2 随机数类(Random)
Random random = new Random();
int num = random.nextInt(10); //产生0-10之间的随机数