Java Basic Source Code (1)--string class

Source: Internet
Author: User
Tags comparable readable serialization

This is the string class above the comments, I use Google Translate, although a bit of grammatical problems, but probably can be translated

/** * The {@code  String} class represents character strings. All * strings literals in Java programs, such as {@code  "abc"}, is * Implemented as instances of this CL The. * <p> * Strings is constant; Their values cannot is changed after they * is created. String buffers support mutable strings. * Because String objects is immutable they can be shared. For example:
{@code String} class represents a string. Character literals in all Java programs, such as {@code "abc"}, are implemented as instances of this class.
Class* string literals in Java programs, such as {@code ' abc 'thisclass  * <p> ** * Because String objects is immutable they can be shared. For example:
The strings are immutable; their values cannot be changed. Created (the meaning of this sentence I personally think should be: has been created can not be modified).
string buffers support variable strings. Because the string object is immutable. So you can share them.
class  for  for for forfor*class.
class {@code String} includes the Check method
* Individual characters of the sequence, used to compare strings
* Search strings, extract substrings, and create
* A copy of a string, all words nonalphanumeric translated into uppercase or
lowercase Case mapping is based on the Unicode standard version
* Specified by {@link Java.lang.Character Character} class.
Describes some of the contents of the String class (check methods, sequence of characters, compare strings, search strings,
* Extract substrings, create a copy of a string, all characters translated large, lowercase,)
* * The Java language provides special support forThe string* Concatenation operator (&nbsp;+&nbsp;), and forConversion of*Other objects to strings. String concatenation is implemented*through the {@code StringBuilder} (or {@code stringbuffer})*classand its {@code append} method.*the conversion of a string is implemented by the ToString () method defined in object that is inherited by all classes in Java .*String Conversions is 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 language provides special support for strings* Join operator (  + ), for converting*other objects to the string. String connection implemented*through {@code StringBuilder} (or {@code stringbuffer})*class and its {@code append} method. *string conversions are implemented by this method*{@code toString}, defined by {@code Object}*inherited by all classes in Java. For additional information*string joins and transformations, see Gosling,joy and Steele,* <i> Java language Specification </i>.   represents the meaning of non-newline spaces
* <p> Unless otherwise noted, passing a <tt>null</tt>thisclass  * thrown.

Unless otherwise noted, passing a null argument to a constructor or a method in this class will result in a nullpointerexception (null pointer exception)

Start learning Now:

 Public Final class implements java.io.Serializable, Comparable<string>, charsequence {

First he is final type, is not modifiable, then implements the Serializable,comparable,charsequence this 3 interface

Serializable: This is a comment on the source code of the Serializablelei class

class class  interfacedo thisinterface* deserialized.  class  * serializable.  Interface

The approximate meaning of the translation is that the serialization of the class is enabled by the class of the Java.io.Serializable interface. Classes that do not implement this interface will not use any state serialization or deserialization, all serializable subtypes are serializable, there are no methods or fields for the serialization interface, and are used only to identify the semantics of the string jargon.

Comparable:

The JDK1.8 document means that the interface strengthens an overall ordering of the objects that implement each of its classes. This sort is called a natural sort of class, and the CompareTo method of the class is called the natural comparison method.

Example (for reference to others)

 Public classPersionImplementsComparable<persion>{String name; intAge ;  PublicPersion (String name,intAge ) {         This. Name =name;  This. Age =Age ; }     PublicString GetName () {returnname; }     Public voidsetName (String name) { This. Name =name; }     Public intGetage () {returnAge ; }     Public voidSetage (intAge ) {         This. Age =Age ; }     Public intcompareTo (persion o) {/** Compares the order of this object with the specified object, returns an integer, 0, or negative number if the object is less than * equals or greater than the specified object*/        returnCompare This. Age,o.age); }     Public Static intCompareLongAge1,Longage2) {        return(Age1>age2?1: (age1==age2?0:-1)); } @Override PublicString toString () {return"persion{" + "name=" + name + ' \ ' + ", age=" + Age + '} '; }}    Public Static voidMain (string[] args) {persion persion2=NewPersion ("World", 23); Persion Persion1=NewPersion ("Ke ji", 21); Persion Persion3=NewPersion ("Wai-gram", 25); List<persion>persionlist=NewArraylist<persion>();        Persionlist.add (Persion2);        Persionlist.add (Persion1);        Persionlist.add (Persion3);  for(persion person1:persionlist) {System.out.println (person1.tostring ()); } System.out.println ("Before the sort ...............");        Collections.sort (persionlist);  for(persion person1:persionlist) {System.out.println (person1.tostring ()); } System.out.println ("After the sort ..............."); }

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 is a readable sequence of char values that provides uniform, read-only access to many different types of char sequences, and char values represent a basic multilingual plane (BMP) or a character in an agent
* * <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, objects, implement <tt>CharSequence</tt> is therefore, in general, * Undefin Ed.
Each object could be implemented by a different class, and there * are no guarantee that each class would be capable of testin G its instances * for equality and those of the other.
It is therefore inappropriate to use * arbitrary <tt>CharSequence</tt> instances as elements in a set or as Ke Ys in * a map. </p>
* * @authorMike McCloskey *@since1.4 * @spec JSR-51*/
This interface does not refine the general contract for the Equals and Hashcode methods. Therefore, a comparison of two object implementationsCharsequence The result is, in general, indeterminate, each object can be implemented by a different class, and there is no guarantee that each class will be able to test its instance to be the same as another class, so use any of the charsequence
An instance is inappropriate as an element in a collection or as a key in a map.

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.
* Returns the length of this sequence of characters, which is a length of 16-bit 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.
* Returns the value at the specified index of char. The index range is from 0 to length ()-1. The first char value of the sequence is zero at index, and the next index is 1.
And so on, just like an array index
* <p>if the <code>char</code> value specified by the index is a
If the value specified by the index of Char is surrogate, the substituted value is returned
* <a href= "{@docRoot}/java/lang/character.html#unicode" &GT;SURROGATE&LT;/A&GT;, the surrogate
* value is returned.
*
* @param index The index of the <code>char</code> value to be returned
* Index of the char value to return with the parameter index
* @return The specified <code>char</code> value
* Returns a specified value of Char
* @throws indexoutofboundsexception
* If the <tt>index</tt> argument is negative or not less than
* <tt>length () </tt>
Exception indexoutofbuoundsexception If the index parameter is negative or not below length ()
*/
char charAt (int index);
* Returns a <code>CharSequence</code> that's 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 a empty sequence is returned.
* Returns a charsequence, which is a sub-sequence of this sequence. A child char begins with the specified index of char value, indexed by the End-1 Char
The value ends, and the length of the returned sequence (chars) is End-start, so if Start==end returns an empty sequence
* @param start the start index, inclusive
Parameter start contains the start index
* @param end the end index, exclusive
* Parameter end end index, exclusive
* @return The specified subsequence
Returns the specified sub-sequence
*
* @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>
*/Exception Indexoutofboundsexception If start or end is negative, if end is greater than length ()
, or if start is greater than 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 would be the length of
* This sequence.
* Returns a string containing the characters in this sequence in the same order as this order, and the length of the string will be the length of this sequence
* @return A string consisting of exactly this sequence of characters
*/returns A string consisting of 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.
* Returns the stream of int, extending the char value from this sequence 0, mapping any character to surrogate code point through an
Explain the way to pass
* <p>if the sequence is mutated while the stream is being read, the
* result is undefined.
* If the sequence is mutated when the stream is read, the result is undefined
* @return A intstream of char values from this sequence
Returns the Intstream of the char value in this sequence
* @since 1.8
*/
Public default Intstream chars () {

Java Basic Source Code (1)--string class

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.