这个是String类上面的注释,我用谷歌翻译翻译的,虽然有点语法上的问题,但是大概都可以翻译出来

/**
* The {@code String} class represents character strings. All
* string literals in Java programs, such as {@code "abc"}, are
* implemented as instances of this class.
* <p>
* Strings are constant; their values cannot be changed after they
* are created. String buffers support mutable strings.
* Because String objects are immutable they can be shared. For example:
{@code String}类表示字符串。所有java程序中的字符文字,例如{@code "abc"},是作为此类的实例实现。
The {@code String} class represents character strings. All
* string literals in Java programs, such as {@code "abc"}, are
* implemented as instances of this class.
* <p>
* Strings are constant; their values cannot be changed after they
* are created. String buffers support mutable strings.
* Because String objects are immutable they can be shared. For example:
字符串是不变的;他们的价值观无法改变已创建(这句话的意思我个人觉得应该是:已经创建就无法修改)。
字符串缓冲区支持可变字符串。因为String对象是不可变的。所以可以共享他们。
* The class {@code String} includes methods for examining
* individual characters of the sequence, for comparing strings, for
* searching strings, for extracting substrings, and for creating a
* copy of a string with all characters translated to uppercase or to
* lowercase. Case mapping is based on the Unicode Standard version
* specified by the {@link java.lang.Character Character} class.
类{@code String}包括检查方法
*序列的各个字符,用于比较字符串
*搜索字符串,提取子字符串,以及创建
*一个字符串的副本,所有字符都翻译成大写或
*小写。案例映射基于Unicode标准版本
*由{@link java.lang.Character Character}类指定。
介绍了String类里面包括的一些内容(检查方法,序列的各个字符,比较字符串,搜索字符串,
* 提取子字符串,创建一个字符串的副本,所有字符翻译大,小写,)
 *  * The Java language provides special support for the string
* concatenation operator (&nbsp;+&nbsp;), and for conversion of
* other objects to strings. String concatenation is implemented
* through the {@code StringBuilder}(or {@code StringBuffer})
* class and its {@code append} method.
* String的转换是通过由java中的所有类继承的Object里面定义的toString()方法实现
* String conversions are implemented through the method
* {@code toString}, defined by {@code Object} and
* inherited by all classes in Java. For additional information on
* string concatenation and conversion, see Gosling, Joy, and Steele,
* * <i>The Java Language Specification</i>.
*  * Java语言为字符串提供特殊支持
 *连接运算符(&nbsp; +&nbsp;),用于转换
 *其他对象到字符串。字符串连接已实现
 *通过{@code StringBuilder}(或{@code StringBuffer})
 *类及其{@code append}方法。
 *字符串转换通过该方法实现
 * {@code toString},由{@code Object}定义
 *由Java中的所有类继承。有关其他信息
 *字符串连接和转换,请参阅Gosling,Joy和Steele,
 * <i> Java语言规范</ i>。
&nbsp;代表不换行空格的意思
 * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
* or method in this class will cause a {@link NullPointerException} to be
* thrown.

除非另有说明,否者将NULL参数传递给构造函数或此类中的方法将导致NullPointerException(空指针异常)

现在开始学习:

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

首先他是final类型的,是不可修改,然后实现了Serializable,Comparable,CharSequence这个3个接口

Serializable:这个是Serializablelei类源码上的注释

* Serializability of a class is enabled by the class implementing the
* java.io.Serializable interface. Classes that do not implement this
* interface will not have any of their state serialized or
* deserialized. All subtypes of a serializable class are themselves
* serializable. The serialization interface has no methods or fields
* and serves only to identify the semantics of being serializable.

 翻译的大概意思是,类的序列化是由java.io.Serializable接口的类启用。不实现此接口的类将不会使用任何状态序列化或反序列化,可序列化的所有子类型都是可序列化的,序列化接口没有方法或字段,仅用于标识可串行话的语义。

Comparable:

  JDK1.8文档的意思是该接口对实现它的每个类的对象加强一个整体排序。这个排序被称为类的自然排序,类的compareTo方法被称为自然比较方法。

  例子(借鉴别人的)

public class Persion implements Comparable<Persion> {
String name;
int age; public Persion(String name, int age) {
this.name = name;
this.age = age;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public int getAge() {
return age;
} public void setAge(int age) {
this.age = age;
}
public int compareTo(Persion o) {
/*
* 比较此对象与指定对象的顺序,如果对象小于
* 等于或大于指定对象,则分别返回整数,零,或负数
* */
return compare(this.age,o.age);
}
public static int compare(long age1,long age2){
return (age1>age2?1:(age1==age2?0:-1));
} @Override
public String toString() {
return "Persion{" +
"name='" + name + '\'' +
", age=" + age +
'}';
} } public static void main(String[] args){
Persion persion2 = new Persion("世界", 23);
Persion persion1 = new Persion("科纪", 21);
Persion persion3 = new Persion("伟克", 25); List<Persion>persionList=new ArrayList<Persion>(); persionList.add(persion2);
persionList.add(persion1);
persionList.add(persion3); for (Persion person1 : persionList) {
System.out.println(person1.toString());
}
System.out.println("排序之前........................"); Collections.sort(persionList);
for (Persion person1 : persionList) {
System.out.println(person1.toString());
}
System.out.println("排序之后........................"); }

CharSequence:

  

/**
* A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
* interface provides uniform, read-only access to many different kinds of
* <code>char</code> sequences.
* A <code>char</code> value represents a character in the <i>Basic
* Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
* href="Character.html#unicode">Unicode Character Representation</a> for details.
  CharSequence是char值的可读序列,该界面提供统一的,只读访问许多不同类型的char序列,char值代表基本多语言平面(BMP)或者代理中的一个字符
* * <p> This interface does not refine the general contracts of the {@link * java.lang.Object#equals(java.lang.Object) equals}
and {@link * java.lang.Object#hashCode() hashCode} methods. The result of comparing two * objects that implement <tt>CharSequence</tt> is therefore, in general, * undefined.
Each object may be implemented by a different class, and there * is no guarantee that each class will be capable of testing its instances * for equality with those of the other.
It is therefore inappropriate to use * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in * a map. </p>
* * @author Mike McCloskey * @since 1.4 * @spec JSR-51 */
此界面不会完善equals和hashCode方法的一般合同。因此,比较两个对象实现CharSequence其结果是,一般情况下,不确定的,每个对象可以由不同的类实现,并且不能保证每个类都能够测试其实例以与另一个类相同,因此,使用任意的CharSequence
实例作为集合中的元素或映射中的键是不合适的。
 public interface CharSequence {
/**
* Returns the length of this character sequence. The length is the number
* of 16-bit <code>char</code>s in the sequence.
*返回此字符序列的长度,这个数字序列是长度为16位char的
 * @return  the number of <code>char</code>s in this sequence
*/
int length();
 * Returns the <code>char</code> value at the specified index.  An index ranges from zero
* to <tt>length() - 1</tt>. The first <code>char</code> value of the sequence is at
* index zero, the next at index one, and so on, as for array
* indexing.
*返回char指定索引处的值。索引范围从0到length()-1.序列的第一个char值在索引为零,下一个索引为1,
以此类推,就像数组索引一样
* <p>If the <code>char</code> value specified by the index is a
如果char由索引指定的值是surrogate,则返回所述替代值
* <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
* value is returned.
*
* @param index the index of the <code>char</code> value to be returned
*参数 index,要返回的char值的索引
* @return the specified <code>char</code> value
*返回 指定值为char
* @throws IndexOutOfBoundsException
* if the <tt>index</tt> argument is negative or not less than
* <tt>length()</tt>
  异常 IndexOutOfBuoundsException 如果index参数为负数或不低于length()
*/
char charAt(int index);
 * Returns a <code>CharSequence</code> that is a subsequence of this sequence.
* The subsequence starts with the <code>char</code> value at the specified index and
* ends with the <code>char</code> value at index <tt>end - 1</tt>. The length
* (in <code>char</code>s) of the
* returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
* then an empty sequence is returned.
* 返回一个CharSequence,这是这个序列的一个子序列。子char以指定索引的char值开始,以索引end-1的char
值结束,返回序列的长度(chars)为end-start,因此如果start==end则返回一个空序列
* @param start the start index, inclusive
  参数 start 包含起始索引
* @param end the end index, exclusive
* 参数 end 结束索引,独占
* @return the specified subsequence
  返回 指定的子序列
*
* @throws IndexOutOfBoundsException
* if <tt>start</tt> or <tt>end</tt> are negative,
* if <tt>end</tt> is greater than <tt>length()</tt>,
* or if <tt>start</tt> is greater than <tt>end</tt>
*/异常 indexOutOfBoundsException 如果start或end为负数,如果end大于length()
      ,或者如果start大于end
CharSequence subSequence(int start, int end);
* Returns a string containing the characters in this sequence in the same
* order as this sequence. The length of the string will be the length of
* this sequence.
*以与此顺序相同的顺序返回包含此序列中的字符的字符串,字符串的长度将是此序列的长度
* @return a string consisting of exactly this sequence of characters
*/ 返回 一个由这个字符序列组成的字符串
public String toString();
 * Returns a stream of {@code int} zero-extending the {@code char} values
* from this sequence. Any char which maps to a <a
* href="{@docRoot}/java/lang/Character.html#unicode">surrogate code
* point</a> is passed through uninterpreted.
* 返回Int的流,从这个序列零扩展char值,映射到surrogate code point的任何字符通过未
解释的方式传递
* <p>If the sequence is mutated while the stream is being read, the
* result is undefined.
*如果序列在流被读取时被突变,则结果是未定义的
 * @return an IntStream of char values from this sequence
  返回 这个序列中的char值的intStream
* @since 1.8
*/
public default IntStream chars() {

java基础源码 (1)--String类的更多相关文章

  1. java基础源码 (6)--ArrayListt类

    原作出处:https://www.cnblogs.com/leesf456/p/5308358.html 简介: 1.ArrayList是一个数组队列,相当于动态数组.与java中的数组相比,它的容量 ...

  2. java基础源码 (2)--StringBuilder类

    Serializable(接口): 是一个IO的序列化接口,实现了这个接口,就代表这个类可以序列化或者反序列化,该接口没有方法或者字段,仅用于标识可串行话的语义. Appendable(接口): /* ...

  3. 源码学习-String类

    最近在扫描CodeDex时报了一个不能使用String.intern()的字符串来做锁对象的告警,对这个问题有疑问查了些资料,顺便学习一下String类的源码. 1.类定义 String 被final ...

  4. JDK源码之String类解析

    一 概述 String由final修饰,是不可变类,即String对象也是不可变对象.这意味着当修改一个String对象的内容时,JVM不会改变原来的对象,而是生成一个新的String对象 主要考虑以 ...

  5. [Java源码解析] -- String类的compareTo(String otherString)方法的源码解析

    String类下的compareTo(String otherString)方法的源码解析 一. 前言 近日研究了一下String类的一些方法, 通过查看源码, 对一些常用的方法也有了更透彻的认识,  ...

  6. String -- 从源码剖析String类

    几乎所有的 Java 面试都是以 String 开始的,String 源码属于所有源码中最基础.最简单的一个,对 String 源码的理解也反应了你的 Java 基础功底. String 是如何实现的 ...

  7. jdk源码理解-String类

    String类的理解 简记录一下对于jdk的学习,做一下记录,会持续补充,不断学习,加油 1.String的hash值的计算方法. hash值的计算方法多种多样,jdk中String的计算方法如下,比 ...

  8. java基础源码 (5)--reflect包-AccessibleObject类

    学习参考博客:https://blog.csdn.net/benjaminzhang666/article/details/9664585AccessibleObject类基本作用 1.将反射的对象标 ...

  9. java基础源码 (3)--Annotation(注解)

    借鉴博客地址:https://www.cnblogs.com/skywang12345/p/3344137.html /** * The common interface extended by al ...

随机推荐

  1. B. Light bulbs

    B. Light bulbs There are NNN light bulbs indexed from 000 to N−1N-1N−1. Initially, all of them are o ...

  2. 新闻网大数据实时分析可视化系统项目——2、linux环境准备与设置

    1.Linux系统常规设置 1)设置ip地址 使用界面修改ip比较方便,如果Linux没有安装操作界面,需要使用命令:vi /etc/sysconfig/network-scripts/ifcfg-e ...

  3. 产品降价、AR技术、功能降级,库克和苹果还有哪些底牌可以打?

    经过十年的高速发展,苹果和iPhone迎来了拐点,他们去年的境况,也连累了一大批的供应商,但如今的苹果财务健康,产业链稳固,在面对经济寒冬和激烈竞争的时候,有很多牌可以打,而且常常会在关键时刻打出来, ...

  4. Jumpserver docker-compose 随手记

    wget  或  git clone   docker  build  -t   jumpserver:v1   .     #构建镜像   docker images vim  jumpserver ...

  5. Spring声明式事物原理分析

    基础准备 pom <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www. ...

  6. helloctf.exe ----攻防世界

    下载附件之后,查壳发现没有壳,运行试试看 很平常的输入代码,然后ida查看一下,开始就发现一个注意的地方,但是还是继续向下看, 结果就是CrackMeJustForFun

  7. Linux远程上传文件

    #对拷文件夹 (包括文件夹本身) scp -r /home/slk root@192.168.1.5:/home # 对拷文件并重命名 scp /home/a.txt root@192.168.1.5 ...

  8. java文件的上传

    文件的上传和下载在web应用中是非常常用,也是非常有用的功能.  例如:发送电子邮件时可以同过上传附件发送文件,OA系统中可以通过上传文件来提交公文,社交网站通过上传图片来自定义头像等等.  例如:下 ...

  9. EXTjs开发————优雅的用extjs写一个柱状图

    简单的写法,extjs可以直接引用插件来写,这里将我发表在百度文库的文档简述下来,有兴趣也可以关注我的百度文库,ID:该用户已失踪. 主要部分的代码: $(document).ready(functi ...

  10. 06.swoole学习笔记--异步tcp服务器

    <?php //创建tcp服务器 $host='0.0.0.0'; $port=; $serv=new swoole_server($host,$port); //设置异步进程工作数 $serv ...