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 11package com .string ;
22
3+ import org .apache .commons .lang .StringUtils ;
4+
35public class EqualsTest {
46 public static void main (String args []) {
57 String str1 ="abc1" ;
@@ -15,5 +17,9 @@ public static void main(String args[]) {
1517 if (str1 .toUpperCase ().equals (str3 .toUpperCase ())){
1618 System .out .println (str1 +"等于" +str3 );
1719 }
20+ //使用StringUtils.equalsIgnoreCase比较大小,既不会空指针,也可以忽略大小写。
21+ if (StringUtils .equalsIgnoreCase (str1 , str2 )) {
22+ System .out .println ("str1等于str2" );
23+ }
1824 }
1925}
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