String源码学习

零散的收获

  1. 数组的元素类型可以通过getComponentType来获取到
  2. 子类型的数组可以赋值给父类型的数组,。但是并不存在继承关系。数组的父类是Object。
  3. 通过声明如下代码来控制需要序列化的field

    private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0];

  4. Java中的char都是以unicode编码来保存字符的,占用2个字节。

  5. might be near -1>>>1. 这句话的意思是,可能会达到Interge.Max_Value,为什么呢? -1的二进制表示是全1.那么>>>之后,就变成了最高位为0,其他全为1,也就是int所表示的最大整数了。此时对这个数字做加法可能会溢出,所以会将a + b > c表示成 a > c - b,就不会有溢出问题了。
  6. Matcher.quoteReplacement方法将输入的字符串转换为其对应的字面值,其实就是讲输入参数中的\和$都替换为两个\,也就等同于字面值了。

常用方法

  • concat

    将两个字符串连接为一个,通过调用两次System.arrayCopy来高效完成,第一次生成一个包含两个string长度的字符数组并将自身拷贝进去,然后将第二个string拷贝到剩下的部分中。

  • replace(char,char)

    replace的实现可以很简单,先直接复制一个,然后逐个替换掉出现的字符即可。但是作者并没有这么实现,而是充分考虑了性能。

    • 如果两个输入字符相同,那么直接返回自身即可。
    • 如果待替换的字符没有出现,那么直接返回自身即可。

    基于上面的两个考虑,实现先判断了两个入参是否相同,如果不同,那么先尝试去寻找这个待替换的字符串,如果找到了,这时才会new一个新的字符数组将内容拷贝过去。

    不得不说,对性能的敏锐和态度,很能看出一个程序员的水准。

  • match

    输入一个正则表达式,判断是否和这个字符串匹配。

  • replaceAll

    将字符串中所有匹配输入正则表达式的部分替换为第二个参数

  • split

    根据给定的序列将字符串分割,可以指定最多分割多少份。

  • format

    类似C语言的格式化语法,参考java.util.Formatter

  • valueOf

    return (obj == null) ? "null" : obj.toString();

*:first-child {
margin-top: 0 !important;
}

body>*:last-child {
margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}

h1 {
font-size: 28px;
color: #000;
}

h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}

h3 {
font-size: 18px;
}

h4 {
font-size: 16px;
}

h5 {
font-size: 14px;
}

h6 {
color: #777;
font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
color: #4183C4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
padding-left: 30px;
}

ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}

dl {
padding: 0;
}

dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}

dl dt:first-child {
padding: 0;
}

dl dt>:first-child {
margin-top: 0px;
}

dl dt>:last-child {
margin-bottom: 0px;
}

dl dd {
margin: 0 0 15px;
padding: 0 15px;
}

dl dd>:first-child {
margin-top: 0px;
}

dl dd>:last-child {
margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}

pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}

pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}

pre code, pre tt {
background-color: transparent;
border: none;
}

kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}

blockquote>:first-child {
margin-top: 0px;
}

blockquote>:last-child {
margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}

/* TABLES
=============================================================================*/

table th {
font-weight: bold;
}

table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}

table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}

table tr:nth-child(2n) {
background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
max-width: 100%
}
-->

String源码学习的更多相关文章

  1. 基于JDK1.8的String源码学习笔记

    String,可能是学习Java一上来就学习的,经常用,但是却往往只是一知半解,甚至API有时也得现查.所以还是老规矩,倒腾源码. 一.java doc 这次首先关注String的doc,因为其实作为 ...

  2. java String源码学习

    public final class String implements java.io.Serializable, Comparable<String>, CharSequence { ...

  3. JDK源码学习--String篇(二) 关于String采用final修饰的思考

    JDK源码学习String篇中,有一处错误,String类用final[不能被改变的]修饰,而我却写成静态的,感谢CTO-淼淼的指正. 风一样的码农提出的String为何采用final的设计,阅读JD ...

  4. JDK1.8源码学习-String

    JDK1.8源码学习-String 目录 一.String简介 String类是Java中最常用的类之一,所有字符串的字面量都是String类的实例,字符串是常量,在定义之后不能被改变. 二.定义 p ...

  5. MVC系列——MVC源码学习:打造自己的MVC框架(四:了解神奇的视图引擎)

    前言:通过之前的三篇介绍,我们基本上完成了从请求发出到路由匹配.再到控制器的激活,再到Action的执行这些个过程.今天还是趁热打铁,将我们的View也来完善下,也让整个系列相对完整,博主不希望烂尾. ...

  6. MVC系列——MVC源码学习:打造自己的MVC框架(三:自定义路由规则)

    前言:上篇介绍了下自己的MVC框架前两个版本,经过两天的整理,版本三基本已经完成,今天还是发出来供大家参考和学习.虽然微软的Routing功能已经非常强大,完全没有必要再“重复造轮子”了,但博主还是觉 ...

  7. MVC系列——MVC源码学习:打造自己的MVC框架(二:附源码)

    前言:上篇介绍了下 MVC5 的核心原理,整篇文章比较偏理论,所以相对比较枯燥.今天就来根据上篇的理论一步一步进行实践,通过自己写的一个简易MVC框架逐步理解,相信通过这一篇的实践,你会对MVC有一个 ...

  8. MVC系列——MVC源码学习:打造自己的MVC框架(一:核心原理)

    前言:最近一段时间在学习MVC源码,说实话,研读源码真是一个痛苦的过程,好多晦涩的语法搞得人晕晕乎乎.这两天算是理解了一小部分,这里先记录下来,也给需要的园友一个参考,奈何博主技术有限,如有理解不妥之 ...

  9. 我的angularjs源码学习之旅2——依赖注入

    依赖注入起源于实现控制反转的典型框架Spring框架,用来削减计算机程序的耦合问题.简单来说,在定义方法的时候,方法所依赖的对象就被隐性的注入到该方法中,在方法中可以直接使用,而不需要在执行该函数的时 ...

随机推荐

  1. 结合tcpdump命令对traceroute深入分析

    昨天突然被问到traceroute的原理,一时竟也说不出来,有些命令平时虽然经常在用,但实际原理确并不了解,趁这次机会就来梳理一下. traceroute:是网络诊断中,用来分析IP包经过那些路由的命 ...

  2. VS2010字体优化

    文本编辑器:Consolas 环境字体:微软雅黑

  3. c - 冒泡/选择排序.

    #include <stdio.h> #define LEN 10 #define TRUE 1 #define FALSE 0 /* 对 10 个数进行排序 */ //选择排序法(值得注 ...

  4. tomcat启动报错总结

    错误一 webapps\ROOT does not exist or is not a readable directory 错误原因:在tomcat的server.xml的context中配置了不存 ...

  5. jQuery自学笔记(四):jQuery DOM节点操作

    获得和设置内容:text( ).html( ) 以及 val( ) text( ) - 设置或返回所选元素的文本内容 html( ) - 设置或返回所选元素的内容(包括 HTML 标记) val( ) ...

  6. nodejs安装过程及视频地址

    说实话在安装的过程中遇到了很多问题,包括npm install connect出错,主要是我之前安装了0.10版本之后安装4.X版本造成的,后面卸载没有卸载完全造成的,后面也就好了,网上说了很多重新设 ...

  7. zip命令的用法

    语法zip [参数] [打包后的文件名] [打包的目录路径] 参数列表-a 将文件转成ASCII模式-F 尝试修复损坏的压缩文件-h 显示帮助界面-m 将文件压缩之后,删除源文件-n 特定字符串,不压 ...

  8. [转]关于Chrome不能登录和同步的解决方法

    原帖地址:http://tieba.baidu.com/p/3086127792?pn=1 在本机的hosts文件(C:\Windows\System32\drivers\etc)里加入下面内容: # ...

  9. C#实现窗体间的通信

    以下将窗体间的几种通信实现方式做一下罗列:首先新建一个窗体Form1,在其中放置一个Textbox.Button控件.再新建一个窗体Form2,其上放置一个Button控件.具体代码示例如下: //F ...

  10. GET方式的中文编码与解码