jdk AbstractStringBuilder实现
一、属性
1.1 value
/*** The value is used for character storage.*/char[] value;
1.2 count
/*** The count is the number of characters used.*/int count;
二、方法
2.1 deleteCharAt
/*** Removes the {@code char} at the specified position in this* sequence. This sequence is shortened by one {@code char}.** <p>Note: If the character at the given index is a supplementary* character, this method does not remove the entire character. If* correct handling of supplementary characters is required,* determine the number of {@code char}s to remove by calling* {@code Character.charCount(thisSequence.codePointAt(index))},* where {@code thisSequence} is this sequence.** @param index Index of {@code char} to remove* @return This object.* @throws StringIndexOutOfBoundsException if the {@code index}* is negative or greater than or equal to* {@code length()}.*/public AbstractStringBuilder deleteCharAt(int index) {if ((index < 0) || (index >= count))throw new StringIndexOutOfBoundsException(index);System.arraycopy(value, index+1, value, index, count-index-1);count--;return this;}
2.2 delete
/*** Removes the characters in a substring of this sequence.* The substring begins at the specified {@code start} and extends to* the character at index {@code end - 1} or to the end of the* sequence if no such character exists. If* {@code start} is equal to {@code end}, no changes are made.** @param start The beginning index, inclusive.* @param end The ending index, exclusive.* @return This object.* @throws StringIndexOutOfBoundsException if {@code start}* is negative, greater than {@code length()}, or* greater than {@code end}.*/public AbstractStringBuilder delete(int start, int end) {if (start < 0)throw new StringIndexOutOfBoundsException(start);if (end > count)end = count;if (start > end)throw new StringIndexOutOfBoundsException();int len = end - start;if (len > 0) {System.arraycopy(value, start+len, value, start, count-end);count -= len;}return this;}
2.3 append
/*** Appends the specified string to this character sequence.* <p>* The characters of the {@code String} argument are appended, in* order, increasing the length of this sequence by the length of the* argument. If {@code str} is {@code null}, then the four* characters {@code "null"} are appended.* <p>* Let <i>n</i> be the length of this character sequence just prior to* execution of the {@code append} method. Then the character at* index <i>k</i> in the new character sequence is equal to the character* at index <i>k</i> in the old character sequence, if <i>k</i> is less* than <i>n</i>; otherwise, it is equal to the character at index* <i>k-n</i> in the argument {@code str}.** @param str a string.* @return a reference to this object.*/public AbstractStringBuilder append(String str) {if (str == null)return appendNull();int len = str.length();ensureCapacityInternal(count + len);str.getChars(0, len, value, count);count += len;return this;}
jdk AbstractStringBuilder实现相关推荐
- JDK源码解析之 Java.lang.AbstractStringBuilder
这个抽象类是StringBuilder和StringBuffer的直接父类,而且定义了很多方法,因此在学习这两个类之间建议先学习 AbstractStringBuilder抽象类 该类在源码中注释是以 ...
- 【JDK源码分析】StringBuilder、StringBuilder、String、AbstractStringBuilder源码解析
前言 String为不可变,StringBuilder.StringBuffer都为可变. 下面是它们之前的关系 为什么String是不可变的? // final修饰,禁止继承String publi ...
- mave工程中的一个类调用另一个聚合工程的一个类_谈谈设计模式:建造者模式在jdk中的体现,它和工厂模式区别?...
背景 建造模式(Builder模式) 假如有一个需求:盖房子,盖房子过程是一致的:打桩.砌墙.封顶.但是房子是各式各样的,最后盖出来的房子可能是高楼或别墅. 根据直接的思路,不用设计模式思想,我们也许 ...
- JDK源码学习路线~每天学一点~每天进步一点点
很多java开发的小伙伴都会阅读jdk源码,然而确不知道应该从哪读起.以下为小编整理的通常所需阅读的源码范围. 标题为包名,后面序号为优先级1-4,优先级递减 1.java.lang 1) Objec ...
- JDK源码(1)-阅读指引
说在最前面的话: 其实JDK源码的阅读,网上资料特别多,我阅读的最主要目的是自己学习,所以我读的可能不那么好,我的角度是从源码和源码对应的注释读起,顺便还能练练英语. 接下来准备对JDK的常见源码进行 ...
- JAVA JDK源码在线阅读
Java的版本是1.8.0_111,我把JDK源码发布到了github上,大家看起来也比较方便,地址: https://github.com/daiqingliang/java_jdk1.8.0_11 ...
- JDK19都出来了~是时候梳理清楚JDK的各个版本的特性了【JDK17特性讲解】
JDK各个版本特性讲解-JDK17特性 一.JAVA17概述 JDK 16 刚发布半年(2021/03/16),JDK 17 又如期而至(2021/09/14),这个时间点特殊,蹭苹果发布会的热度 ...
- 新版本jdk(9、11、12、13、14)特性
目录 背景 jdk9新特性 目录结构的改变 模块化系统 要解决的问题 概念 实现目标 示例 jShell命令 多版本兼容jar包 接口中的私有方法 钻石操作符(泛型)的升级 try语句的升级 下划线命 ...
- JDK源码阅读之路【不断更新】
前言 为什么阅读源码? 学习设计模式和思维.总之,知道自己有多菜,在不断学习的过程中发现自身不足并弥补,才能进步. 如何阅读 阅读顺序参考:https://blog.csdn.net/qq_21033 ...
- 聊聊Java8之后的JDK升级内容(看这一篇就够了)
聊聊Java8之后的JDK升级内容(看这一篇就够了) 背景 从 JDK 8 到 JDK 17 的新特性 JDK8 回顾 JDK9 JDK10 JDK11 JDK12 JDK13 JDK14 JDK15 ...
最新文章
- mysql字段定义成text类型的严重影响查询性能
- 随机森林RF中的特征重要性的计算公式VIM
- android button背景随心搭配
- “TypeError: list indices must be integers or slices, not str”有关报错解决方案
- Cisco BFD双向转发检测技术部署案例
- ButterKnife 8.4.0 @BindView 失败,nullpointerexception
- 我和我的广告前端代码(六):webpack工程合并、也许我不需要gulp
- 工业交换机在城市智慧轨道交通中的应用分析
- tcp wireshark 过滤syn_使用 WireShark 分析 TCP/IP 三次握手 和 四次挥手
- 二级c语言需要记库函数不,【2017年必备】计算机等级二级C语言上机考试题库(熟记必过,不看后悔).doc...
- iis php7页面空白,iis 无法显示htm页面问题解决
- ResNeX论文概述
- 霍夫森林(Hough Forest)目标检测算法
- PIC16F877A开发板 数码管计数器实验
- html自动调用js函数,使用HTML按钮调用JavaScript函数
- 关于另类BT下载的想法
- 阿里、腾讯、知乎裁员 那些被裁的程序员怎么办?
- PDF文档一键自动生成目录和书签
- javafx 实现绘图板
- 程序员真的可以轻松来一套苹果全家桶吗
热门文章
- java m e 获取公钥_Java如何生成公钥和私钥?
- java线程volatile_多线程与高并发(四)volatile关键字
- android-gradle-plugin3.0.1源码分析
- 同事乱用 Redis 卡爆,我真是醉了
- 你写的代码要被 GitHub 存在北极啦!期限是 1000 年!
- Linux下一次数据仓库进行迁移记录
- python变量、运算符、要求从键盘输入用户名和密码,校验格式是否符合规则,如果不符合,打印出不符合的原因,并提示重新输入练习
- 大学生使用计算机的情况英语作文,关于网络的大学生英语作文(精选10篇)
- 没有编程基础可以学python_没有任何编程基础可以直接学习python语言吗?学会后能够做什么?...
- @configuration注解_SpringBoot注解大全,收藏一波!!!