当前位置:网站首页>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
边栏推荐
- Please, stop painting star! This has nothing to do with patriotism!
- Soft test software designer full truth simulation question (including answer analysis)
- 免费抽奖 | 《阿巴豆》探索未来系列盲盒数字版权作品全网首发!
- Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
- Transition technology from IPv4 to IPv6
- Introduction to software engineering - Chapter 6 - detailed design
- Research and investment strategy report of China's sodium sulfate industry (2022 Edition)
- Template Engine Velocity Foundation
- The difference between the lazy mode of singleton mode and the evil mode
- PR basic clip operation / video export operation
猜你喜欢

Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022

模板引擎Velocity 基础

How to restore the system with one click on Lenovo laptop

sql刷题584. 寻找用户推荐人

Introduction to software engineering - Chapter 6 - detailed design

【flask入门系列】Cookie与Session

Detailed explanation of activity life cycle and startup mode

Free lottery | explore the future series of blind box digital copyright works of "abadou" will be launched on the whole network!

多线程使用不当导致的 OOM

SystemVerilog structure (II)
随机推荐
National Security Agency (NSA) "sour Fox" vulnerability attack weapon platform technical analysis report
What is the effect of choosing game shield safely in the game industry?
阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外
redis -- 数据类型及操作
In aks, use secret in CSI driver mount key vault
多线程使用不当导致的 OOM
字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化
ACL 2022 | 分解的元学习小样本命名实体识别
sql刷题584. 寻找用户推荐人
Machine learning 11 clustering, outlier discrimination
The difference between the lazy mode of singleton mode and the evil mode
Jojogan practice
Transition technology from IPv4 to IPv6
Girls who want to do software testing look here
判断链表是否是回文链表
换掉UUID,NanoID更快更安全!
Computed property “xxx“ was assigned to but it has no setter.
mysql -- explain性能优化
Mysql database - Advanced SQL statement (2)
中国锦纶长丝缝纫线发展预测与投资方向研究报告(2022版)