码迷,mamicode.com
首页 > 其他好文 > 详细

String和StringBuilder

时间:2019-09-08 21:48:58      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:key   pre   int   star   capacity   spl   com   port   concat   

 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

标签:key   pre   int   star   capacity   spl   com   port   concat   

原文地址:https://www.cnblogs.com/lovemeng1314/p/11488610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!