当前位置:网站首页>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
边栏推荐
猜你喜欢

【C补充】【字符串】按日期排序显示一个月的日程

【牛客网刷题系列 之 Verilog快速入门】~ 优先编码器电路①

SQL注入漏洞(Mysql与MSSQL特性)

整形数组合并【JS】

What is the effect of choosing game shield safely in the game industry?

Pytest learning notes (13) -allure of allure Description () and @allure title()
![[flask introduction series] cookies and session](/img/2e/d50e0a032c4ec48935cb5df206a29b.png)
[flask introduction series] cookies and session

sql刷题584. 寻找用户推荐人
![[live broadcast appointment] database obcp certification comprehensive upgrade open class](/img/50/83a533f4e8a60f90e03b991385c08d.jpg)
[live broadcast appointment] database obcp certification comprehensive upgrade open class

sql刷题586. 订单最多的客户
随机推荐
ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
How to cancel automatic search and install device drivers for laptops
想做软件测试的女孩子看这里
Leetcode records - sort -215, 347, 451, 75
[Supplément linguistique c] déterminer quel jour est demain (date de demain)
Girls who want to do software testing look here
Rhcsa Road
How to maintain the laptop battery
阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
How to restore the system of Sony laptop
整形数组合并【JS】
中国一次性卫生用品生产设备行业深度调研报告(2022版)
中国锦纶长丝缝纫线发展预测与投资方向研究报告(2022版)
Hi Fun Summer, play SQL planner with starrocks!
在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
Babbitt | yuan universe daily must read: Naixue coin, Yuan universe paradise, virtual stock game Do you understand Naixue's tea's marketing campaign of "operation pull full"
重磅披露!上百个重要信息系统被入侵,主机成为重点攻击目标
Introduction to software engineering - Chapter 6 - detailed design
Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
(27) Open operation, close operation, morphological gradient, top hat, black hat