这个是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. 【剑指Offer面试编程题】题目1513:二进制中1的个数--九度OJ

    题目描述: 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 输入: 输入可能包含多个测试样例. 对于每个输入文件,第一行输入一个整数T,代表测试样例的数量.对于每个测试样例输入为一个 ...

  2. Linux centosVMware MySQL主从介绍、准备工作、配置主、配置从、测试主从同步

    一.MySQL主从介绍 MySQL主从又叫做Replication.AB复制.简单讲就是A和B两台机器做主从后,在A上写数据,另外一台B也会跟着写数据,两者数据实时同步的 MySQL主从是基于binl ...

  3. 注册模块上线前安全测试checklist

    许多应用系统都有注册模块,正常用户通过注册功能,获得应用系统使用权限:而非法用户通过注册模块,则是为了达到不可告人的目的,非法用户可以通过注册模块与服务端进行交互(一切用户输入都不可信),因此系统上线 ...

  4. HTTP协议调试工具汇总

    前言 本文收集了大量抓包工具,近40款,涵盖了各种开发语言(Java,C#,Delphi,C,C++,Objective-C,Node.js,Go,Python).各类前端(GUI,TUI,CUI,W ...

  5. LINQ---查询变量

    LINQ查询可以返回两种类型的结果----枚举和标量(scalar)的单一值 namespace ConsoleApplication46 { class Program { static void ...

  6. HiBench成长笔记——(6) HiBench测试结果分析

    Scan Join Aggregation Scan Join Aggregation Scan Join Aggregation Scan Join Aggregation Scan Join Ag ...

  7. nuxt.js 初始化 npm run dev 报错

    在初始化 npm install 了基本依赖后: npm run dev 报错: error in ./server/index.js Module build failed: Error: Plug ...

  8. java实现下划线转驼峰

    废话少说,直接上代码 import java.util.regex.Matcher; import java.util.regex.Pattern; public class Temp { publi ...

  9. Windows下 dmp文件的产生

    一.windows下的崩溃捕获windows程序当遇到异常,没有try-catch或者try-catch也无法捕获到的异常时,程序就会自动退出.windows系统默认是不产生程序dmp文件的.dump ...

  10. UCENTER同步登录工作原理和配置要点

    ucenter的同步登录原理: 1)Ucenter是和uc_client同步的.每个PHP应用,加入了UCENTER后,都会在主目录下有个UC_CLIENT目录.这个目录里,都有一个client.PH ...