当前位置:网站首页>Detailed explanation of string's trim() and substring()
Detailed explanation of string's trim() and substring()
2022-07-01 17:02:00 【Michael_.】
If substring() Write only one parameter in the method :
trim() Method :
give an example :
String str = " 32143243 2 ";
System.out.println(str.trim());
Output ( Remove the spaces at the beginning and end ):
Let's look at the source code for analysis
If there are spaces at the beginning or end of a string , Call substring() Cut it off ;
If there is no space , Then return the string
substring() Method :
give an example :
String str = "321432432";
System.out.println(str.substring(0,3));
Output ( Intercepted subscript 0-3 Substring of ):
Check the source code for analysis
When the input start index and end index do not meet the conditions , Throw an exception ;
When entering the start index =0 And when the end index is equal to the length of the string , Returns the original string ;
otherwise new One String object ( Address change )
If substring() Write only one parameter in the method :
String str = "321432432";
System.out.println(str.substring(3));
Output ( Intercepted subscript 3 Numbers to the end ):
Check the source code for analysis :
When writing only one starting index :
Less than 0, disqualification , Throw an exception ;
Start to compare the index with the string length , If the difference is less than 0, Throw an exception ;
If the difference is greater than 0, Start with this index , The length of the string is the end index new One String object
边栏推荐
- (27) Open operation, close operation, morphological gradient, top hat, black hat
- 剑指 Offer 20. 表示数值的字符串
- 智能运维实战:银行业务流程及单笔交易追踪
- Alibaba cloud, Zhuoyi technology beach grabbing dialogue AI
- 中国乙腈市场预测与战略咨询研究报告(2022版)
- Introduction to software engineering - Chapter 6 - detailed design
- ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
- There is a new breakthrough in quantum field: the duration of quantum state can exceed 5 seconds
- 重磅披露!上百个重要信息系统被入侵,主机成为重点攻击目标
- SystemVerilog-结构体(二)
猜你喜欢
Detailed explanation of activity life cycle and startup mode
【PyG】文档总结以及项目经验(持续更新
PR basic clip operation / video export operation
Internet News: "20220222" get together to get licenses; Many products of Jimi have been affirmed by consumers; Starbucks was fined for using expired ingredients in two stores
How to restore the system of Sony laptop
Rhcsa Road
荣威 RX5 的「多一点」产品策略
Redis6.0 new features
多线程使用不当导致的 OOM
How to restore the system with one click on Lenovo laptop
随机推荐
How to repair the laptop that cannot connect to the wireless network
Template engine velocity Foundation
ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
ACL 2022 | 分解的元学习小样本命名实体识别
Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
National Security Agency (NSA) "sour Fox" vulnerability attack weapon platform technical analysis report
巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
[C language supplement] judge which day tomorrow is (tomorrow's date)
Report on Market Research and investment prospects of ammonium dihydrogen phosphate industry in China (2022 Edition)
多线程并发之CountDownLatch阻塞等待
[Supplément linguistique c] déterminer quel jour est demain (date de demain)
SystemVerilog-结构体(二)
P2592 [zjoi2008] birthday party (DP)
AI高考志愿填报:大厂神仙打架,考生付费围观
挖财学堂班主任给的证券账户安全吗?能开户吗?
【C語言補充】判斷明天是哪一天(明天的日期)
Transition technology from IPv4 to IPv6
【C语言补充】判断明天是哪一天(明天的日期)