javaSE---常用类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javaSE---常用类相关的知识,希望对你有一定的参考价值。
2.2 字符串处理(2)
1 public class Panduan {
2
3 public static void main(String[] args) {
4 String s="lina520lina520lina";
5 System.out.println(s.contains("lina"));//true
6 System.out.println(s.contains("zcw"));//false
7 // System.out.println(s.contains(‘l‘));//no
8 System.out.println(s.startsWith("lina"));//true
9 System.out.println(s.endsWith("lina"));//True
10 System.out.println(s.startsWith("lina", 7));//True
11 System.out.println(s.equalsIgnoreCase("LINA520LINA520LINA"));//True
12 System.out.println(s.equals("lina520lian520Lina"));//false
13 System.out.println(s.isEmpty());//false
14 System.out.println(s.intern());//lina520lina520lina
15 System.out.println(s.matches("\\d"));//false
16 System.out.println("\\d".matches(s));//false
17 System.out.println("lina520lina520lina".matches(s));//true
18
19
20
21
22
23
24
25 }
26
27 }
1 public class Pingjie {
2
3 public static void main(String[] args) {
4 String s="lina520lina520lina";
5 s.concat("520zcw");
6 //"lina520lina520lina"
7 s=s.concat("520zcw");//必须要赋值
8 //lina520lina520lina520zcw
9 System.out.println(s);
10 System.out.println("zcw".concat("lina").concat("zcw").concat("lina"));
11 //zcwlinazcwlina字符串的拼接
12 }
13
14 }
1 public class Replace {
2
3 public static void main(String[] args) {
4 String s="lina520lina520lina";
5 //System.out.println(s.replace("lina", "zcw"));
6 //zcw520zcw520zcw
7 System.out.println(s.replace(‘l‘, ‘z‘));//不会出现“”与‘‘之间的替换
8 //zina520zina520zina
9 System.out.println(s.replaceAll("\\d", "772"));
10 //lina772772772lina772772772lina
11 System.out.println(s.replaceFirst("\\d", "772"));
12 //lina77220lina520lina
13 System.out.println(s.replace(s, "nima"));
14 //nima target:目标
15 }
1 import java.io.UnsupportedEncodingException;
2 import java.util.Arrays;
3
4 public class Zhuanhuan {
5
6 public static void main(String[] args) throws UnsupportedEncodingException {
7 String s="lina520lina520lina";
8 byte[] a=s.getBytes();
9 // System.out.println(Arrays.toString(a));
10 // [108, 105, 110, 97, 53, 50, 48, 108, 105, 110, 97, 53, 50, 48, 108, 105, 110, 97]
11
12 byte[] b=s.getBytes("UTF-8");
13 byte[] c=s.getBytes("GBK");
14 System.out.println(Arrays.toString(b));
15 System.out.println(Arrays.toString(c));
16
17
18 char [] cc=new char [100];
19 cc [0] =‘z‘;
20 cc [1] =‘c‘;
21 cc [2] =‘w‘;
22 cc.toString();
23 System.out.println(cc);//字符型数组化字符串
24
25 s.getChars(0, 4, cc, 3);//从字符串取第0到第4个字符(左闭右开)
26 System.out.println(Arrays.toString(cc));
27 //[z, c, w, l, i, n, a}
28
29 char [] ccc = s.toCharArray();//字符串化字符数组
30
31 System.out.println(Arrays.toString(ccc));
32 //[l, i, n, a, 5, 2, 0, l, i, n, a, 5, 2, 0, l, i, n, a]
33
34 String code=s.toUpperCase();
35 System.out.println(code);
36 //LINA520LINA520LINA
37
38 String str=code.toLowerCase();
39 System.out.println(str);
40 //lina520lina520lina
41
42
43
44
45 }
46
47 }
以上是关于javaSE---常用类的主要内容,如果未能解决你的问题,请参考以下文章