I. Introduction to String
Package: Java.lang.string,java.lang provides the basic class for programming using the Java programming language.
Implementation: Public final class String implements Java.io.Serializable, Comparable<string>, charsequence{}
Where: Java.io.Serializable is a serialization-related interface;
Java.lang.CharSequence is a readable sequence of cahr values;
Java.lang.comparable<string> forcibly sorts each object of the class that implements it.
Class Introduction:
/** * The <code>String</code> class represents character strings. All * strings literals in Java programs, such as <code> "abc" </CODE>, is * implemented as instances of this CLA SS. * <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: * <p><blockquote><pre> * String str = "ABC"; * </pre></blockquote><p> * is equivalent to: * <p><blockquote><pre> * Char data[] = {' A ', ' B ', ' C '}; * String str = new string (data); * </pre></blockquote><p> * Here is some more examples of what strings can be used: * <P><BLOCKQ uote><pre> * SYSTEM.OUT.PRINTLN ("abc"); * String CDE = "CDE"; * SYSTEM.OUT.PRINTLN ("abc" + CDE); * String c = "abc". substring (2,3); * String d = cde.substring (1, 2); * </pre></blockquote> * <p> * The class <code>String</code> includes methods for examining * Individual characters of the sequ ence, for comparing strings, for * searching strings, for extracting substrings, and for creating a * copy of a string wit H all characters translated to uppercase or to * lowercase. Case mapping was based on the Unicode standard version * specified by the {@linkJava.lang.Character Character} class. * <p> * The Java language provides special support for the string * concatenation operator ( + ), and for conversion of * other objects to strings. String concatenation is implemented * through the <code>StringBuilder</code> (or <code>stringbuffer </code>) * Class and its <code>append</code> method. * String conversions is implemented through the method * <CODE>TOSTRING</CODE>, defined by <code>object </code> * Inherited by all classes in Java. For additional information on * string concatenation and conversion, see Gosling, Joy, and Steele, * <i>the Java Lan Guage Specification</i>. * * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor * or method in this CL The cause a {@linkNullPointerException} to is * thrown. * * <p>a <code>String</code> represents A String in the UTF-16 format * in which <em>supplementary Characters</em> is represented by <em>surrogate * pairs</em> (see the section <a href= "Character.ht Ml#unicode ">unicode * Character representations</a> in the <code>Character</code> class for * more I nformation). * Index values refer to <code>char</code> code units, so a supplementary * character uses. Positions in A & Lt;code>string</code>. * <p>the <code>String</code> class provides methods for dealing with * Unicode code points (i.e., Charac ters), in addition-those for * Dealing with Unicode code units (i.e., <code>char</code> values). * * @authorLee Boynton *@authorArthur van Hoff *@version1.204, 06/09/06 *@seejava.lang.object#tostring () *@seeJava.lang.StringBuffer *@seeJava.lang.StringBuilder *@seeJava.nio.charset.Charset *@sinceJDK1.0*/
1. String class represents strings. The author is Lee Boynton. All string literals in Java, such as "ABC", are implemented as instances of this class.
2, the definition of the string class has the "final" keyword, the string is a constant, cannot be changed after creation.
3. The Java language provides special support for string concatenation symbols ("+") and for converting other objects to strings. string concatenation is StringBuilder
implemented through the (or StringBuffer
) class and its append
methods.
String conversions are Object
implemented through the methods defined by the class toString
, which can be inherited by all classes in Java.
4. Unless otherwise noted, passing a null argument to a construction method or method in this class throws NullPointerException.
Second, the method
1, char charAt (int index): Returns the character at the specified index of the string.
SYSTEM.OUT.PRINTLN ("abc". CHARAT (1)); // The result is: B
Source:
Public Char charAt (int index) { if (Index < 0) | | (Index >= count)) { thrownew stringindexoutofboundsexception (index); } return Value[index + offset]; }
/***/ privatefinalchar value[];
Public String () {
this. offset = 0; this. Count = 0; This New Char [0]; }
2, int codepointat (int index): Returns the Unicode code value of the character at the specified index.
SYSTEM.OUT.PRINTLN ("abc". CODEPOINTAT (0)); // Results:
3, int codepointbefore (int index):
4, int codepointcount (int beginindex,int endIndex)
5, int compareTo (String anotherstring)
6, int comparetoignorecase (String str)
7, String concat (String str)
8. Boolean contains (Charsequence s)
9. Boolean contentequence
Copyvalueof
EndsWith
equals
Equalsignorecase
Format
GetBytes
Hashcode
IndexOf
Intern
IsEmpty
LastIndexOf
Length
Matches
Replace
ReplaceAll
Split
StartsWith
Tostring
ValueOf
"Just for java--Foundation"--section II: String