File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com .string ;
2
2
3
+ import org .apache .commons .lang .StringUtils ;
4
+
3
5
public class EqualsTest {
4
6
public static void main (String args []) {
5
7
String str1 ="abc1" ;
@@ -15,5 +17,9 @@ public static void main(String args[]) {
15
17
if (str1 .toUpperCase ().equals (str3 .toUpperCase ())){
16
18
System .out .println (str1 +"等于" +str3 );
17
19
}
20
+ //使用StringUtils.equalsIgnoreCase比较大小,既不会空指针,也可以忽略大小写。
21
+ if (StringUtils .equalsIgnoreCase (str1 , str2 )) {
22
+ System .out .println ("str1等于str2" );
23
+ }
18
24
}
19
25
}
Original file line number Diff line number Diff line change
1
+ package com .string ;
2
+
3
+ /**
4
+ * @Author: EnjoyCoding
5
+ * @Date: 2020\3\14 0014 22:51
6
+ * @Description:
7
+ */
8
+ public class SplitDemo {
9
+ /**
10
+ * 使用索引访问用 String 的 split 方法得到的数组时,需做最后一个分隔符后有无
11
+ * 内容的检查,否则会有抛 IndexOutOfBoundsException 的风险。
12
+ */
13
+ public void splitStr () {
14
+ String str = "a,b,c,," ;
15
+ String [] ary = str .split ("," );
16
+ // 预期大于 3,结果是 3
17
+ int length =ary .length ;
18
+ System .out .println (ary [length - 1 ]);
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments