StringBuilder类subSequence()方法 (StringBuilder Class subSequence() method)

  • subSequence() method is available in java.lang package.

    subSequence()方法在java.lang包中可用。

  • subSequence() method is used to return the new set of a character sequence that is a subset of this sequence.

    subSequence()方法用于返回字符序列的新集合,该字符序列是该序列的子集。

  • subSequence() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    subSequence()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • subSequence() method may throw an exception at the time of character sequence.

    subSequence()方法在字符序列时可能会引发异常。

    IndexOutOfBoundsException – This exception may throw when end_seq > length or when st_seq > end_seq or when st_seq or end_seq are less than 0.

    IndexOutOfBoundsException-当end_seq> length或st_seq> end_seq或st_seq或end_seq小于0时,可能引发此异常。

Syntax:

句法:

    public CharSequence subSequence(int st_seq, int end_seq);

Parameter(s):

参数:

  • int st_seq – represents the beginning index of this character sequence.

    int st_seq –表示此字符序列的开始索引。

  • int end_seq – represents the ending index of this character sequence.

    int end_seq –表示此字符序列的结束索引。

Return value:

返回值:

The return type of this method is CharSequence, it returns the given subsequence of this character sequence.

此方法的返回类型为CharSequence ,它返回此字符序列的给定子序列。

Example:

例:

// Java program to demonstrate the example
// of subSequence(int st_seq, int end_seq)
// method of StringBuilder
public class SubSequence {public static void main(String[] args) {// Creating an StringBuilder object
StringBuilder st_b = new StringBuilder("Java World ");
// Display st_b object
System.out.println("st_b = " + st_b);
// By using subSequence() method is to return the sequence
// from the given index 0 to index 3 (but it does not include
// last index i.e. 4)
CharSequence cs = st_b.subSequence(0, 4);
System.out.println("st_b.subSequence(0,4) = " + cs);
}
}

Output

输出量

st_b = Java World
st_b.subSequence(0,4) = Java

翻译自: https://www.includehelp.com/java/stringbuilder-subsequence-method-with-example.aspx

Java StringBuilder subSequence()方法与示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. setlength java_Java StringBuilder setLength()方法与示例

    StringBuilder类setLength()方法setLength()方法在java.lang包中可用. setLength()方法用于在将字符序列替换为新字符序列时设置字符序列的长度,因此该序 ...

  3. java codepointbefore_Java StringBuilder codePointBefore()方法与示例

    StringBuilder类codePointBefore()方法codePointBefore()方法在java.lang包中可用. codePointBefore()方法用于表示给定索引和数组索引 ...

  4. java user directory,Java ProcessBuilder directory()方法与示例

    语法:public File directory (); public ProcessBuilder directory (File dir); ProcessBuilder类directory()方 ...

  5. Java序列化魔术方法及其示例使用

    在上一篇文章中, 您需要了解有关Java序列化的所有知识 ,我们讨论了如何通过实现Java序列化来启用类的可序列化性. Serializable接口. 如果我们的类未实现Serializable接口, ...

  6. catalog java,Java Connection getCatalog()方法与示例

    通常,目录是一个目录,其中包含有关数据集,文件或数据库的信息.而数据库目录中包含所有数据库,基本表,视图(虚拟表),同义词,值范围,索引,用户和用户组的列表. Connection接口的getCata ...

  7. filepermission java,Java FilePermission getActions()方法与示例

    FilePermission类getActions()方法getActions()方法在java.io包中可用. getActions()方法用于检查此FilePermission和给定对象在路径名和 ...

  8. java方法参数Bundle,Java ResourceBundle keySet()方法及示例

    ResourceBundle类keySet()方法keySet()方法在java.util包中可用. keySet()方法用于从此ResourceBundle及其超级捆绑包中获取所有现有键,以在Set ...

  9. java exec waitfor,Java Process waitFor()方法与示例

    流程类waitFor()方法在java.lang包中提供了waitFor()方法. waitFor()方法用于使当前正在运行的线程在需要时等待,直到由该Process对象表示的进程完成其终止为止. 当 ...

最新文章

  1. 如何在Docker容器中挂载主机目录
  2. python3 去除列表中重复的元素 保存原来顺序
  3. rtmp服务器与播放器的交互
  4. 区块链学堂(7):Geth 搭建私有网络-实战
  5. XidianOJ 1176 ship
  6. android 配置ADB环境
  7. vue项目实现登录(sessionStorage 存储 token)
  8. linux改狗命令,linux安装安全狗
  9. [转]git merge 与 git rebase的区别
  10. CMMI与Agile敏捷开发比较之二:需求管理篇(兼谈用敏捷实现和满足CMMI的ReqM过程域)...
  11. 亚马逊遭遇15万人联名抗议:AI刷脸可以,但卖给政府不OK
  12. mysql 增删改查操作笔记
  13. 使用 CP2102通过串口下载程序到STM32F103中 (MCUISP)
  14. mysql中 经纬度用什么类型存储_MySQL数据库之***mysql中经度纬度字段用什么存储(关于mysql的float和decimal区别)...
  15. 东沃电子:瞬态电压抑制二极管选型指南
  16. 局域网ip扫描工具_中科院网络工程师网络安全视频教程10端口扫描
  17. 零基础学习 iOS 开发?如何系统学习 iOS ?
  18. 文件和文件夹的操作——文件流的使用
  19. 尚上优选社区团购业务流程及微服务技术实现
  20. CentOS7 搭建Janus服务

热门文章

  1. vue2.5.2版本 :MAC设置应用在127.0.0.1:80端口访问; 并将127.0.0.1指向www.yours.com ;问题“ Invalid Host header”
  2. css实现鼠标覆盖显示大图
  3. 分享几道经典的javascript面试题
  4. vue使用v-for循环,动态修改element-ui的el-switch
  5. HDUOJ 1428
  6. VisualVM介绍使用
  7. 洛谷-P1160 队列安排
  8. 阻塞/非阻塞/同步/异步方法和多线程的关系?没有任何关系,俩不挨着
  9. MongoDB系列二
  10. 【摘录】C语言中利用 strtok函数进行字符串分割