类的方法
2022-09-23 01:29:30 0 举报
AI智能生成
登录查看完整内容
类的方法
作者其他创作
大纲/内容
boolean equals(Object obj);
public native int hashCode();
String toString();
Class getClass();
void finalize();
Object clone
System.gc();
Object
equals相等,哈希值一定相等;哈希值相等,equals不一定相等。
System.out.println(Byte.MAX_VALUE);
System.out.println(Byte.MIN_VALUE);
Byte b1 = Byte.valueOf(\"123\");
byte b2 = Byte.parseByte(\"11\");
Integer i1 = Integer.valueOf(\"213\");
int i2 = Integer.parseInt(\"456\");
把字符串转换成对应的类型
byte类型,作用完全一样
int类型,作用完全一样
整数系列:Byte/Short/Integer/Long
System.out.println(Float.MAX_VALUE);
System.out.println(Float.MIN_VALUE);
Float f1 = Float.valueOf(\"132.432\");
float f2 = Float.parseFloat(\"123.456\");
float类型,作用完全一样
Float/Double
System.out.println(Integer.toBinaryString(10));
把一个整数转成二进制字符串
Character.isAlphabetic('+')
Character.isLetter('9')
是否是字母
Character.isDigit('a')
是否是数字
Character.isWhitespace('\\t')
是否是空白
Character.isUpperCase('a')
是否是大写
Character.isLowerCase('A')
是否是小写
Character.toUpperCase('z')
转成大写
Character.toLowerCase('Z')
转成小写
判断字符的类型
封装类
数据拷贝
System.currentTimeMillis()
计算机元年 1970-1-1 0:0:0
从计算机元年到当前经过的毫秒数
jvm调用垃圾收集,不会立刻执行
System.exit(0);
退出虚拟机
System.in/System.out/System.err
输入的字节流
System
Date d1 = new Date();
当前日期
Date d2 = new Date(3239371932791L);
从计算机元年经过3239371932791L毫秒数到的日期
System.out.println(d1.before(d2));
System.out.println(d1.after(d2));
判断日期的前后
true/false
Date
LocalDate d1 = LocalDate.now();
返回本地的当前时间
指定年月日的日期
指定时分秒的时间
LocalDateTime dt = LocalDateTime.now();
日期时间类
local本地的
BigInteger i1 = new BigInteger(\"123123212313213213123131313213132132131\");
BigInteger i2 = new BigInteger(\"123123212313213213123131313213132132131\");
bigNumber大数字
System.out.println(i1.add(i2)); System.out.println(i1.subtract(i2)); System.out.println(i1.multiply(i2)); System.out.println(i1.divide(i2));
BigDecimal j1 = new BigDecimal(\"123123212313213213123.131313213132132131\");
BigDecimal j2 = new BigDecimal(\"123123212313213213123.131313213132132131\");
BigDecimal大小数
System.out.println(j1.add(j2)); System.out.println(j1.subtract(j2)); System.out.println(j1.multiply(j2)); System.out.println(j1.divide(j2));
快捷键:Alt + Shift + A;同时修改多行
SimpleDateFormat sdf = new SimpleDateFormat(\"yyyy-MM-dd hh:mm:ss:S a E\");
简单的日期格式化
Date parse = sdf.parse(str);
把字符串解析成具体日期
SimpleDateFormat
日期类
int length = \"hello\".length();
求长度
char charAt = \"hello\".charAt(0);
根据位置获取字符
int indexOf = \"hello\".indexOf('l');
int indexOf3 = \"hello world\
从下标5开始往后找第一个l位置
int indexOf5 = \"hello\".lastIndexOf('l');
从后往前找
int indexOf7 = \"hello world\
从下标5开始往前找第一个l位置
boolean contains = \"hello world\".contains(\"or\");
包含
boolean equals = \"hello\".equals(\"HELLO\");
boolean eic = \"hello\".equalsIgnoreCase(\"HELLO\");
是否相等
String substring = \"hello world\".substring(4);
String substring2 = \"hello world\
int compareTo = \"hello\".compareTo(\"hzwew\");
比较大小,一样0,对象大返回正,参数大返回负数
int compareTo2 = \"hello\".compareToIgnoreCase(\"hzwew\");
忽略大小写比较大小
String[] split = \"www.baidu.com\".split(\"[.]\");
String trim = \" hello world \".trim();
去掉字符串两边空白
boolean empty = \"\".isEmpty();
判断是否为空
String upperCase = \"hello\".toUpperCase();
String lowerCase = \"HELLO\".toLowerCase();
转换大小写
boolean startsWith = \"hello\".startsWith(\"he\");
boolean endsWith = \"hello\".endsWith(\"he\");
是否以开头和结尾
String replaceAll = \"h2e3l4l5o6\".replaceAll(\"\\\\d\
String replaceFirst = \"hello\".replaceFirst(\"l\
替换
byte[] bytes = \"abcde\".getBytes();
返回byte数组
char[] charArray = \"abcde\".toCharArray();
返回char数组
String的非静态
String valueOf = String.valueOf(true);
将其他类型转成字符串
String s = \"aaa\";String concat = s.concat(\"bbb\");
String join = String.join(\"-\
字符串链接
String format = String.format(\
格式化
String的静态
类
收藏
0 条评论
回复 删除
下一页