这个是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. java并发(一):初探线程的创建

    线程的创建两种方式 创建线程有四种方式,今天主要演示的是两种:继承Thread,实现Runable接口 继承Thread创建线程 import lombok.extern.slf4j.Slf4j; @ ...

  2. Windows系统(服务器)忘记管理员登录密码:

    windows sever2003忘记密码:使用老毛桃PE进入然后修改密码,重启即可. windows sever2008忘记密码:可按该网址的方法即可解决:http://www.jb51.net/a ...

  3. vue - 封装input

    input子组件 <el-input :value="value" placeholder="请输入内容" size="small" ...

  4. 074、Java面向对象之构造方法重载

    01.代码如下: package TIANPAN; class Book { // 定义一个新的类 private String title; // 书的名字 private double price ...

  5. 产品原型 UI 设计工具

    产品原型设计工具 Balsamiq Mockups Axure RP 图像处理.绘制工具 ps,AI 跨平台 UI开发工具 QT , Unity3D

  6. Maven 使用Nexus搭建Maven私服

    Maven学习 (四) 使用Nexus搭建Maven私服 为什么要搭建nexus私服,原因很简单,有些公司都不提供外网给项目组人员,因此就不能使用maven访问远程的仓库地址,所以很有必要在局域网里找 ...

  7. css限制文字显示字数长度,超出部分自动用省略号显示,防止溢出到第二行

    为了保证页面的整洁美观,在很多的时候,我们常需要隐藏超出长度的文字.这在列表条目,题目,名称等地方常用到. 效果如下: 未限制显示长度,如果超出了会溢出到第二行里.严重影响用户体验和显示效果. 我们在 ...

  8. Xilinx COE文件格式小记

    官方的参考文档是:https://www.xilinx.com/support/documentation/sw_manuals/xilinx11/cgn_r_coe_file_syntax.htm ...

  9. NFS实战

    博客实践: (1) nfs server导出/data/application/web,在目录中提供wordpress; (2) nfs client挂载nfs server导出的文件系统至/var/ ...

  10. POJ 3233:Matrix Power Series 矩阵快速幂 乘积

    Matrix Power Series Time Limit: 3000MS   Memory Limit: 131072K Total Submissions: 18450   Accepted:  ...