String和StringBuilder

Posted lovemeng1314

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了String和StringBuilder相关的知识,希望对你有一定的参考价值。

 1 import java.util.Collections;
 2 
 3 import static com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolver.length;
 4 //java字符串不会改变,除非重新赋值
 5 public class 字符串 {
 6     public static void main(String[] args) {
 7         String str = "44";
 8         int num = Integer.parseInt(str);
 9         str = String.valueOf(num);
10 
11         str = "dfa,sdf,adsf,asd,fasd,fas,df";
12         String[] strings = str.split(",");
13         str = String.join(",", strings);
14 
15         //左闭右开区间
16         String string = str.substring(3,6);
17 
18         char c = string.charAt(1);
19         int d = string.compareTo(string);
20         String  ss = string.concat(string);
21         boolean b = ss.contains("a");
22         b = ss.startsWith("s");
23         b = ss.endsWith("s");
24         b = ss.isEmpty();
25 
26         b = ss.matches("a");
27 
28         ss = ss.replaceAll("sf" ,"asdf");
29         ss = ss.replaceFirst("sf" ,"asdf");
30 
31         char[] chars = ss.toCharArray();
32 
33         ss = ss.toLowerCase();
34         ss = ss.toUpperCase();
35         ss = ss.trim();
36 
37         //StringBuilder
38 
39         StringBuilder stringBuilder = new StringBuilder("");
40         stringBuilder.append("sdf");
41         int aa = stringBuilder.capacity();
42         int bb = stringBuilder.length();
43 
44         stringBuilder.delete(1, 2);//左闭右开
45 
46         stringBuilder.reverse();
47         stringBuilder.deleteCharAt(1);
48         stringBuilder.insert(0, "0000");
49 
50     }
51 }

 

以上是关于String和StringBuilder的主要内容,如果未能解决你的问题,请参考以下文章

从为什么String=String谈到StringBuilder和StringBuffer

String,StringBuffer与StringBuilder的区别

String,StringBuilder,StringBuffer的区别

Java中的String,StringBuilder,StringBuffer三者的区别

Java中的String,StringBuilder,StringBuffer三者的区别

Java--String中“+”,StringBuffer和StringBuilder