< prev index next >

src/java.base/share/classes/java/lang/String.java

Print this page




  61  *     String str = new String(data);
  62  * </pre></blockquote><p>
  63  * Here are some more examples of how strings can be used:
  64  * <blockquote><pre>
  65  *     System.out.println("abc");
  66  *     String cde = "cde";
  67  *     System.out.println("abc" + cde);
  68  *     String c = "abc".substring(2,3);
  69  *     String d = cde.substring(1, 2);
  70  * </pre></blockquote>
  71  * <p>
  72  * The class {@code String} includes methods for examining
  73  * individual characters of the sequence, for comparing strings, for
  74  * searching strings, for extracting substrings, and for creating a
  75  * copy of a string with all characters translated to uppercase or to
  76  * lowercase. Case mapping is based on the Unicode Standard version
  77  * specified by the {@link java.lang.Character Character} class.
  78  * <p>
  79  * The Java language provides special support for the string
  80  * concatenation operator (&nbsp;+&nbsp;), and for conversion of
  81  * other objects to strings. String concatenation is implemented
  82  * through the {@code StringBuilder}(or {@code StringBuffer})
  83  * class and its {@code append} method.
  84  * String conversions are implemented through the method
  85  * {@code toString}, defined by {@code Object} and
  86  * inherited by all classes in Java. For additional information on
  87  * string concatenation and conversion, see Gosling, Joy, and Steele,
  88  * <i>The Java Language Specification</i>.
  89  *
  90  * <p> Unless otherwise noted, passing a {@code null} argument to a constructor
  91  * or method in this class will cause a {@link NullPointerException} to be
  92  * thrown.
  93  *
  94  * <p>A {@code String} represents a string in the UTF-16 format
  95  * in which <em>supplementary characters</em> are represented by <em>surrogate
  96  * pairs</em> (see the section <a href="Character.html#unicode">Unicode
  97  * Character Representations</a> in the {@code Character} class for
  98  * more information).
  99  * Index values refer to {@code char} code units, so a supplementary
 100  * character uses two positions in a {@code String}.
 101  * <p>The {@code String} class provides methods for dealing with
 102  * Unicode code points (i.e., characters), in addition to those for
 103  * dealing with Unicode code units (i.e., {@code char} values).
 104  *
 105  * <p>Unless otherwise noted, methods for comparing Strings do not take locale
 106  * into account.  The {@link java.text.Collator} class provides methods for
 107  * finer-grain, locale-sensitive String comparison.








 108  *
 109  * @author  Lee Boynton
 110  * @author  Arthur van Hoff
 111  * @author  Martin Buchholz
 112  * @author  Ulf Zibis
 113  * @see     java.lang.Object#toString()
 114  * @see     java.lang.StringBuffer
 115  * @see     java.lang.StringBuilder
 116  * @see     java.nio.charset.Charset
 117  * @since   1.0
 118  */
 119 
 120 public final class String
 121     implements java.io.Serializable, Comparable<String>, CharSequence {
 122 
 123     /**
 124      * The value is used for character storage.
 125      *
 126      * @implNote This field is trusted by the VM, and is a subject to
 127      * constant folding if String instance is constant. Overwriting this




  61  *     String str = new String(data);
  62  * </pre></blockquote><p>
  63  * Here are some more examples of how strings can be used:
  64  * <blockquote><pre>
  65  *     System.out.println("abc");
  66  *     String cde = "cde";
  67  *     System.out.println("abc" + cde);
  68  *     String c = "abc".substring(2,3);
  69  *     String d = cde.substring(1, 2);
  70  * </pre></blockquote>
  71  * <p>
  72  * The class {@code String} includes methods for examining
  73  * individual characters of the sequence, for comparing strings, for
  74  * searching strings, for extracting substrings, and for creating a
  75  * copy of a string with all characters translated to uppercase or to
  76  * lowercase. Case mapping is based on the Unicode Standard version
  77  * specified by the {@link java.lang.Character Character} class.
  78  * <p>
  79  * The Java language provides special support for the string
  80  * concatenation operator (&nbsp;+&nbsp;), and for conversion of
  81  * other objects to strings. For additional information on string
  82  * concatenation and conversion, see <i>The Java&trade; Language Specification</i>.






  83  *
  84  * <p> Unless otherwise noted, passing a {@code null} argument to a constructor
  85  * or method in this class will cause a {@link NullPointerException} to be
  86  * thrown.
  87  *
  88  * <p>A {@code String} represents a string in the UTF-16 format
  89  * in which <em>supplementary characters</em> are represented by <em>surrogate
  90  * pairs</em> (see the section <a href="Character.html#unicode">Unicode
  91  * Character Representations</a> in the {@code Character} class for
  92  * more information).
  93  * Index values refer to {@code char} code units, so a supplementary
  94  * character uses two positions in a {@code String}.
  95  * <p>The {@code String} class provides methods for dealing with
  96  * Unicode code points (i.e., characters), in addition to those for
  97  * dealing with Unicode code units (i.e., {@code char} values).
  98  *
  99  * <p>Unless otherwise noted, methods for comparing Strings do not take locale
 100  * into account.  The {@link java.text.Collator} class provides methods for
 101  * finer-grain, locale-sensitive String comparison.
 102  *
 103  * @implNote The implementation of the string concatenation operator is left to
 104  * the discretion of a Java compiler, as long as the compiler ultimately conforms
 105  * to <i>The Java&trade; Language Specification</i>. For example, the {@code javac} compiler
 106  * may implement the operator with {@code StringBuffer}, {@code StringBuilder},
 107  * or {@code java.lang.invoke.StringConcatFactory} depending on the JDK version. The
 108  * implementation of string conversion is typically through the method {@code toString},
 109  * defined by {@code Object} and inherited by all classes in Java.
 110  *
 111  * @author  Lee Boynton
 112  * @author  Arthur van Hoff
 113  * @author  Martin Buchholz
 114  * @author  Ulf Zibis
 115  * @see     java.lang.Object#toString()
 116  * @see     java.lang.StringBuffer
 117  * @see     java.lang.StringBuilder
 118  * @see     java.nio.charset.Charset
 119  * @since   1.0
 120  */
 121 
 122 public final class String
 123     implements java.io.Serializable, Comparable<String>, CharSequence {
 124 
 125     /**
 126      * The value is used for character storage.
 127      *
 128      * @implNote This field is trusted by the VM, and is a subject to
 129      * constant folding if String instance is constant. Overwriting this


< prev index next >