基础类型常用方法总结

一: String类在java.lang包中,java使用String类创建一个字符串变量,字符串变量属于对象。java把String类声明的final类,不能有类。String类对象创建后不能修改,由0或多个字符组成,包含在一对双引号之间
1.0 :字符串比较
1.1:public int compareTo(String anotherString)//该方法是对字符串内容按字典顺序进行大小比较,通过返回的整数值指明当前字符串与参数字符串的大小关系。若当前对象比参数大则返回正整数,反之返回负整数,相等返回0。
1.2:public int compareToIgnore(String anotherString)//与compareTo方法相似,但忽略大小写。
1.3:public boolean equals(Object anotherObject)//比较当前字符串和参数字符串,在两个字符串相等的时候返回true,否则返回false。
1.4:public boolean equalsIgnoreCase(String anotherString)//与equals方法相似,但忽略大小写。

2.0 :字符串中字符的大小写转换
2.0:public String toLowerCase()//返回将当前字符串中所有字符转换成小写后的新串
2.1:public String toUpperCase()//返回将当前字符串中所有字符转换成大写后的新串

3.0 : 字符串中字符的替换
3.0 : public String replace(char oldChar, char newChar)//用字符newChar替换当前字符串中所有的oldChar字符,并返回一个新的字符串。
3.1 : public String replaceFirst(String regex, String replacement)//该方法用字符replacement的内容替换当前字符串中遇到的第一个和字符串regex相匹配的子 串,应将新的字符串返回。
3.2 : public String replaceAll(String regex, String replacement)//该方法用字符replacement的内容替换当前字符串中遇到的所有和字符串regex相匹配的子串, 应将新的字符串返回。

4.0 : 其他类方法
4.0 : String trim()//截去字符串两端的空格,但对于中间的空格不处理

二: Integer 类型
2.0 : integer 的值范围为-2^31---2^31-1(-2147483647---2147483648)
2.1 : toBinaryString转化成二进制码
toHexString 十六进制转换
toOctalString 八进制转换
2.2 : parseInt(String s, int radix)String s :表示是一个十进制字符串的表示形式 int radix: 表示将字符串转化为整数
例:Integer.parseInt("444",16) = 9 将字符串444转化成一个16进制的整数
2.3 : decode(String s)此方法能把8 16 10进制的字符串形式转成十进制整形。
2.4 : sum(int i, int j)求和
max(int i, int j)最大值
min(int i, int j)最小值

三 : math
3.0 : abs 绝对值; Math.PI π值;
3.1 : Math.toDegrees 弧度转化为角度 Math.toRadians 角度转化为弧度
3.2 : Math.sqrt 求开方 Math.pow 求某数的任意次方
Math.sqrt(x):平方根 Math.pow(x,y):x的y次方
3.3 : Math.sin(double a);Math.cos(double a) 三角正弦余弦

四:date类型
4.0: after​(Date when);before​(Date when)判断改时间是否在指定时间前后

五: base64位加密解密
5.0 String str = "你是谁";
String desc = Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8));
System.out.println("加密后的字符串为:"+desc);

String unDecodeStr=new String(Base64.getDecoder().decode(desc),StandardCharsets.UTF_8);
System.out.println("解密后的字符串为"+unDecodeStr);

原文地址:https://www.cnblogs.com/juniorjava/p/8142938.html