浅谈Java的String中的subString()方法
方法如下:
public String substring(int beginIndex, int endIndex)
第一个int为开始的索引,对应String数字中的开始位置,
第二个是截止的索引位置,对应String中的结束位置
1、取得的字符串长度为:endIndex - beginIndex;
2、从beginIndex开始取,到endIndex结束,从0开始数,其中不包括endIndex位置的字符
如:
"hamburger".substring(4, 8) returns "urge" "smiles".substring(1, 5) returns "mile"
取长度大于等于3的字符串a的后三个子字符串,只需a.subString(a.length()-3, a.length());
手册中的具体说明如下:
substring
public String substring(int beginIndex, int endIndex)
Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.
Examples:
"hamburger".substring(4, 8) returns "urge"
"smiles".substring(1, 5) returns "mile"
Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex
以上就是小编为大家带来的浅谈Java的String中的subString()方法的全部内容了,希望对大家有所帮助,多多支持脚本之家~
相关文章
Spring MVC中的Controller进行单元测试的实现
本文主要介绍了如何对Spring MVC中的Controller进行单元测试的实现,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2022-02-02
Java异常处理UncaughtExceptionHandler使用实例代码详解
当一个线程由于未捕获异常即将终止时,Java虚拟机将使用thread . getuncaughtexceptionhandler()查询线程的uncaughtException处理程序,并调用处理程序的uncaughtException方法,将线程和异常作为参数传递2023-03-03
Spring Boot分段处理List集合多线程批量插入数据的解决方案
大数据量的List集合,需要把List集合中的数据批量插入数据库中,本文给大家介绍Spring Boot分段处理List集合多线程批量插入数据的解决方案,感兴趣的朋友跟随小编一起看看吧2024-04-04
Java的MyBatis+Spring框架中使用数据访问对象DAO模式的方法
Data Access Object数据访问对象模式在Java操作数据库部分的程序设计中经常被使用到,这里我们就来看一下Java的MyBatis+Spring框架中使用数据访问对象DAO模式的方法:2016-06-06
解决restlet client报错No response.Is the cer
这篇文章主要介绍了解决restlet client报错No response.Is the certificate valid? Click here to check.问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2024-01-01


最新评论