Note: String

String

boolean startsWith (String prefix)

Tests if this string starts with the specified prefix.
此字符串是否以指定的前缀开始测试。

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 indexendIndex - 1
Thus the length of the substring is endIndex-beginIndex
返回一个新字符串,它是此字符串的一个子。该子字符串从指定的beginIndex,并扩展到索引endIndex的字符 - 1。这样子串的长度为endIndex的-beginIndex。
例子:
"hamburger".substring(4, 8) returns "urge"
"smiles".substring(1, 5) returns "mile"

String substring (int beginIndex)

Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.
返回一个新字符串,它是此字符串的一个子。然后子始于指定索引处的字符,一直到此字符串的结尾。
Examples:
"unhappy".substring(2) returns "happy"
"Harbison".substring(3) returns "bison"
"emptiness".substring(9) returns "" (an empty string)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • java中String的常用方法 1、length()字符串的长度 例:char chars[]={'a','b'...
    赤赤有名阅读 2,105评论 0 10
  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 12,779评论 0 33
  • 前言 回顾 我们讲到了String的equals和==的区别: equals根据你编写的方法体来进行比较,而==是...
    LeeZer阅读 399评论 0 0
  • 坐立不安是陆思琪这一整天的写照,事实上从昨天傍晚接到老公林家平的一个电话后,她便开始心乱如麻,怎么也无法平静下来!...
    二求人生阅读 471评论 1 1
  • 昨晚为了做自己不能够完成的事情,我从10点多回到宿舍后便开始忙。一直觉得能找到好的主题来完成这个任务。然而并没有什...
    轩窗记梦阅读 225评论 0 1