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

vulnhub靶场-hacksudo - Thor

Computed property “xxx“ was assigned to but it has no setter.

软件工程导论——第六章——详细设计

sql刷题586. 订单最多的客户

National Security Agency (NSA) "sour Fox" vulnerability attack weapon platform technical analysis report
![[C language foundation] 12 strings](/img/42/9c024eb08eb935fe66c3aaac7589d8.jpg)
[C language foundation] 12 strings

整形数组合并【JS】

Basic usage of Frida

重磅披露!上百个重要信息系统被入侵,主机成为重点攻击目标

Detailed explanation of activity life cycle and startup mode
随机推荐
【C語言補充】判斷明天是哪一天(明天的日期)
Redis6.0 新功能
GameFramework食用指南
Basic usage of Frida
SQL question brushing 1050 Actors and directors who have worked together at least three times
【flask入门系列】Cookie与Session
How to cancel automatic search and install device drivers for laptops
How to restore the system of Sony laptop
AI高考志愿填报:大厂神仙打架,考生付费围观
China sorbitol Market Forecast and investment strategy report (2022 Edition)
How to solve the keyboard key failure of notebook computer
《中国智慧环保产业发展监测与投资前景研究报告(2022版)》
想做软件测试的女孩子看这里
Rhcsa Road
How to repair the laptop that cannot connect to the wireless network
sql刷题584. 寻找用户推荐人
中国酶制剂市场预测与投资战略研究报告(2022版)
Cookies and session keeping technology
Judge whether a binary tree is a balanced binary tree
阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外