前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Java——字符串操作

Java——字符串操作

作者头像
说故事的五公子
发布2022-05-09 15:27:40
4150
发布2022-05-09 15:27:40
举报
代码语言:javascript
复制
 1 /**
 2  *  java字符串操作
 3  * @author wydream
 4  *
 5  */
 6 
 7 public class StringTest {
 8 
 9     public static void main(String[] args) {
10         String str="abCdeFg";
11         
12         //1.length():统计字符串长度
13         System.out.println(str.length());
14         
15         //2.indexOf:查找指定字符再字符串中的位置
16         System.out.println(str.indexOf("b"));
17         
18         //3.toUpperCase:小写转大写
19         System.out.println(str.toUpperCase());
20         
21         //4.toLowerCase:大写转小写
22         System.out.println(str.toLowerCase());
23         
24         //5.substring:截取字符串
25         System.out.println(str.substring(0,3));
26         System.out.println(str.substring(3));
27         
28         //6.replaceAll:替换当前字符串中指定的内容
29         str.replaceAll("ab", "xy");
30         System.out.println(str);
31         
32         //7.trim:去掉当前字符串中两端的空格
33         str="  adeg efe efe ";
34         System.out.println(str.trim());
35         
36         //8.+:字符串拼接
37         String str1="I LOVE ";
38         String str2="YOU";
39         System.out.println(str1+str2);
40         
41         //9 将字符串变为整数
42         String str3="123";
43         int num=Integer.parseInt(str3);
44         System.out.println(num);
45         
46         
47     }
48     
49 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-07-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档