当前位置:网站首页>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
边栏推荐
- Leetcode 216 combined summation III -- backtracking method
- [flask introduction series] cookies and session
- Flux d'entrées / sorties et opérations de fichiers en langage C
- 【C语言补充】判断明天是哪一天(明天的日期)
- 判断二叉树是否为二叉搜索树
- (27) Open operation, close operation, morphological gradient, top hat, black hat
- Is the securities account given by the head teacher of goucai school safe? Can I open an account?
- sql刷题584. 寻找用户推荐人
- Determine whether the linked list is a palindrome linked list
- SQL注入漏洞(Mysql与MSSQL特性)
猜你喜欢

Leetcode records - sort -215, 347, 451, 75

Rhcsa Road

美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告

Flux d'entrées / sorties et opérations de fichiers en langage C

英特尔开源深度学习工具库 OpenVINO,将加大与本土软硬件方合作,持续开放
![[mathematical modeling] [matlab] implementation of two-dimensional rectangular packing code](/img/de/1f572c62a0d034da9a8acb5c2f9602.jpg)
[mathematical modeling] [matlab] implementation of two-dimensional rectangular packing code

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

游戏行业安全选择游戏盾,效果怎么样?

Pytest learning notes (13) -allure of allure Description () and @allure title()

C语言输入/输出流和文件操作
随机推荐
How to use etcd to realize distributed /etc directory
【Kotlin】高阶函数介绍
《中国智慧环保产业发展监测与投资前景研究报告(2022版)》
走进微信小程序
FRP intranet penetration, reverse proxy
[Supplément linguistique c] déterminer quel jour est demain (date de demain)
AI高考志愿填报:大厂神仙打架,考生付费围观
Flux d'entrées / sorties et opérations de fichiers en langage C
越来越多地使用 SLO 来实现可观测性|DevOps
SystemVerilog structure (II)
The difference between the lazy mode of singleton mode and the evil mode
判断链表是否是回文链表
判断一棵二叉树是否为平衡二叉树
Machine learning 11 clustering, outlier discrimination
(1) CNN network structure
Computed property “xxx“ was assigned to but it has no setter.
The amazing open source animation library is not only awesome, but also small
sql刷题627. 变更性别
【flask入门系列】Cookie与Session
中国酶制剂市场预测与投资战略研究报告(2022版)