您的位置:首页 > 编程语言 > Java开发

JAVASE入门基础知识整理笔记篇(九)

2019-05-07 10:15 190 查看

异常:
Throwable类
/
Error Exception
| |
Unchecked Checked Runtime
Exception Exception Exception

Error:这类错误不需要程序员管理
Exception:异常
检查时异常|编译时异常:如果程序一旦出现检查时异常,程序必须要经过处理,否则无法运行
运行时异常:增强程序的健壮性就可以处理
一般运行时异常都会直接或者间接的继承自RuntimeException

常见的运行时异常:
1.空指针 NullPointerException
2.数组越界异常 ArrayIndexOutOfBoundsException
3.负数异常|数组的长度为负数异常 NegativeArraySizeException
4.数学异常 ArithmeticException
5.类型转换异常 ClassCastException
6.数字转换异常 NumberFormatException

throw 制造异常
throws 抛出异常
捕获异常 try…catch
try {
可能会出现异常的代码;
} catch (FileNotFoundException e) {
如果出现对应的异常执行的代码
} catch (NullPointerException e){
} catch (Exception e){
} finally{
无论是否出现异常,一定会执行的代码
}

注意:
1.如果try中的代码出现异常,下面的代码不会执行,直接执行对应的catch中的代码
2.一个try至少存在一个或者多个catch
3.catch中捕获异常的顺序从小到大写

1.char charAt(int index) 返回指定索引处的 char 值。
2.int codePointAt(int index) 返回指定索引处的字符(Unicode 代码点)。
3.int compareTo(String anotherString) 按字典顺序比较两个字符串。
相等为0 ,如果this比参数对象大返回整数,否则返回负数
4.compareToIgnoreCase(String str) 按字典顺序比较两个字符串,不考虑大小写
5.String concat(String str) 将指定字符串连接到此字符串的结尾。
6.boolean contains(CharSequence s) 当且仅当此字符串包含指定的 char 值序列时,返回 true。
7.static String copyValueOf(char[] data) 返回指定数组中表示该字符序列的 String。
8.boolean endsWith(String suffix) 测试此字符串是否以指定的后缀结束。
9.boolean startsWith(String prefix) 测试此字符串是否以指定的前缀开始。
10.byte[] getBytes() 字符串转字节数组
11.int indexOf(String str) 返回指定子字符串在此字符串中第一次出现处的索引。
12.String replace(char oldChar, char newChar)返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 得到的。
13.String[] split(String regex)根据给定正则表达式的匹配拆分此字符串。
14.String substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串。
15.String substring(int beginIndex, int endIndex)返回一个新字符串,它是此字符串的一个子字符串。 结束位置索引获取不到
16.char[] toCharArray() 将此字符串转换为一个新的字符数组。
17.String toLowerCase()
18.String toUpperCase() 使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
19.String trim()返回字符串的副本,忽略前导空白和尾部空白。
20.static String valueOf(int i) 返回 int 参数的字符串表示形式。

1.char charAt(int index) 返回指定索引处的 char 值。
2.int codePointAt(int index) 返回指定索引处的字符(Unicode 代码点)。
3.int compareTo(String anotherString) 按字典顺序比较两个字符串。
相等为0 ,如果this比参数对象大返回整数,否则返回负数
4.compareToIgnoreCase(String str) 按字典顺序比较两个字符串,不考虑大小写
5.String concat(String str) 将指定字符串连接到此字符串的结尾。
6.boolean contains(CharSequence s) 当且仅当此字符串包含指定的 char 值序列时,返回 true。
7.static String copyValueOf(char[] data) 返回指定数组中表示该字符序列的 String。
8.boolean endsWith(String suffix) 测试此字符串是否以指定的后缀结束。
9.boolean startsWith(String prefix) 测试此字符串是否以指定的前缀开始。
10.byte[] getBytes() 字符串转字节数组
11.int indexOf(String str) 返回指定子字符串在此字符串中第一次出现处的索引。
12.String replace(char oldChar, char newChar)返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 得到的。
13.String[] split(String regex)根据给定正则表达式的匹配拆分此字符串。
14.String substring(int beginIndex) 返回一个新的字符串,它是此字符串的一个子字符串。
15.String substring(int beginIndex, int endIndex)返回一个新字符串,它是此字符串的一个子字符串。 结束位置索引获取不到
16.char[] toCharArray() 将此字符串转换为一个新的字符数组。
17.String toLowerCase()
18.String toUpperCase() 使用默认语言环境的规则将此 String 中的所有字符都转换为大写。
19.String trim()返回字符串的副本,忽略前导空白和尾部空白。
20.static String valueOf(int i) 返回 int 参数的字符串表示形式。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: