-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjava_lang
94 lines (71 loc) · 2.82 KB
/
java_lang
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
数据类型包装类
Byte
Character
Integer
Long
Float
Double
Boolean
Short
// Integer 类
Integer a = new Integer(10);
Integer b = new Integer("11");
a.compareTo(b); // int a>b 1 a=b 0 a<b -1
a.equals(b); // boolean a=b true a!=b false
a.byteValue(); // byte -128~127 范围是一个字节
a.intValue(); // int 型返回此对象
a.shortValue();
a.longValue();
a.floatValue();
a.doubleValue();
a.toString();
String d = "10101110";
int e = Integer.parseInt(d,2); // System.out.println(e); int 通过类Integer调用,输出为字符串按照二进制转化为整型后数值为174
int e = Integer.valueOf(d); // Integer 返回一个保存指定 String 值的 Integer 对象
// Character 类
char[] c = new char[] {'2','f','D'};
Character.isDigit(c[0]); // boolean 是否为数字
Character.isLetter(); // 是否为字母
Character.isLowerCase(); // 是否为小写字母
Character.isUpperCase(); // 是否为大写字母
Character.isWhitespace(); // 是否为空白字符
Character.toUpperCase(); // 指定字母的大写形式
Character.toLowerCase(); // 指定字母的小写形式
// String 类
String s = "abc";
String s1 = new String("abd");
s.length();
s1.equals(s); // 使用 == 比较两个对象在内存中存储的地址是否一样
s1.equalsIgnoreCase(s); // 忽略大小写判断字符串内容是否相同
String s2 = s1.concat(s);
String s2 = s + s1 + "Hello" + 233; // 用 + 进行连接时,要求连接内容至少有一个是字符串
char c = s.charAt(2); // c 为第三个字符
s.indexOf("a"); // int 搜索字符串第一次出现的索引
s.lastIndexOf("b"); // int 搜索字符串最后一次出现的索引
s.substring(1,2); // String 提取两索引位置之间的字符串,包含开头不包含结尾,若只给一个函数则到提取末尾
s.trim(); // 去掉前后空格
// String 类的字符串创建后是不能够改变的,所能改变的只有对象的引用,因此会产生大量冗余
// StringBuffer 类是可变的
StringBuffer 的构造方法:
StringBuffer(); // 构造一个字符串缓冲区,初始容量16个字符
StringBuffer(String); // 构造一个字符串缓冲区,初始化内容为指定字符串
StringBuffer(int); // 构造一个字符串缓冲区,初始化容量为指定字符数
s1.insert(int,s); // 从指定位置插入字符串
s1.append(s); // 在末尾追加字符串
s1.length();
s1.setCharAt(int,char); // 替换指定位置字符
s1.toString();
s1.reverse(); // 反转字符串
s1.delete(intStart,intEnd); // 从 start 到 end-1 删除
s1.replace(intStart,intEnd,s); // 从 start 到 end-1 替换掉
// Math 类
sin cos
pow(a,b) // a 的 b 次方
sqrt(a) // 正平方根
abs(a) // 绝对值
ceil(a) // 向上取整
floor(a) // 向下取整
rint(a) // double 取最近整数,但返回类型为double .0
round(a) // int 取最近整数
// Class 类
// Object 类 所有类的父类