String Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
The String
class represents character strings.
[Android.Runtime.Register("java/lang/String", DoNotGenerateAcw=true)]
public sealed class String : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable, Java.Lang.ICharSequence, Java.Lang.IComparable, System.Collections.Generic.IEnumerable<char>
[<Android.Runtime.Register("java/lang/String", DoNotGenerateAcw=true)>]
type String = class
inherit Object
interface ISerializable
interface IJavaObject
interface IDisposable
interface IJavaPeerable
interface ICharSequence
interface seq<char>
interface IEnumerable
interface IComparable
- Inheritance
- Attributes
- Implements
Remarks
The String
class represents character strings. All string literals in Java programs, such as "abc"
, are implemented as instances of this class.
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: <blockquote>
String str = "abc";
</blockquote>
is equivalent to: <blockquote>
char data[] = {'a', 'b', 'c'};
String str = new String(data);
</blockquote>
Here are some more examples of how strings can be used: <blockquote>
System.out.println("abc");
String cde = "cde";
System.out.println("abc" + cde);
String c = "abc".substring(2,3);
String d = cde.substring(1, 2);
</blockquote>
The class 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 java.lang.Character Character
class.
The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. For additional information on string concatenation and conversion, see The Java™ Language Specification.
Unless otherwise noted, passing a null
argument to a constructor or method in this class will cause a NullPointerException
to be thrown.
A String
represents a string in the UTF-16 format in which <em>supplementary characters</em> are represented by <em>surrogate pairs</em> (see the section Unicode Character Representations in the Character
class for more information). Index values refer to char
code units, so a supplementary character uses two positions in a String
.
The String
class provides methods for dealing with Unicode code points (i.e., characters), in addition to those for dealing with Unicode code units (i.e., char
values).
Unless otherwise noted, methods for comparing Strings do not take locale into account. The java.text.Collator
class provides methods for finer-grain, locale-sensitive String comparison.
Added in 1.0.
Java documentation for java.lang.String
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Constructors
String() |
Creates an empty string. |
String(Byte[]) |
Constructs a new |
String(Byte[], Charset) |
Constructs a new |
String(Byte[], Int32) |
Obsolete.
Allocates a new |
String(Byte[], Int32, Int32) |
Constructs a new |
String(Byte[], Int32, Int32, Charset) |
Constructs a new |
String(Byte[], Int32, Int32, Int32) |
Obsolete.
Allocates a new |
String(Byte[], Int32, Int32, String) |
Constructs a new |
String(Byte[], String) |
Constructs a new |
String(Char[]) |
Initializes this string to contain the given |
String(Char[], Int32, Int32) |
Initializes this string to contain the given |
String(Int32[], Int32, Int32) |
Allocates a new |
String(String) |
Constructs a new string with the same sequence of characters as |
String(StringBuffer) |
Allocates a new string that contains the sequence of characters currently contained in the string buffer argument. |
String(StringBuilder) |
Allocates a new string that contains the sequence of characters currently contained in the string builder argument. |
Properties
CaseInsensitiveOrder |
A Comparator that orders |
Class |
Returns the runtime class of this |
Handle |
The handle to the underlying Android instance. (Inherited from Object) |
IsBlank |
Returns |
IsEmpty |
Returns |
JniIdentityHashCode | (Inherited from Object) |
JniPeerMembers | |
PeerReference | (Inherited from Object) |
ThresholdClass |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. (Inherited from Object) |
ThresholdType |
This API supports the Mono for Android infrastructure and is not intended to be used directly from your code. (Inherited from Object) |
Methods
CharAt(Int32) |
Returns the |
Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
CodePointAt(Int32) |
Returns the character (Unicode code point) at the specified index. |
CodePointBefore(Int32) |
Returns the character (Unicode code point) before the specified index. |
CodePointCount(Int32, Int32) |
Returns the number of Unicode code points in the specified text
range of this |
CompareTo(String) |
Compares two strings lexicographically. |
CompareToIgnoreCase(String) |
Compares two strings lexicographically, ignoring case differences. |
Concat(String) |
Concatenates the specified string to the end of this string. |
Contains(ICharSequence) |
Returns true if and only if this string contains the specified sequence of char values. |
Contains(String) |
Returns true if and only if this string contains the specified sequence of char values. |
ContentEquals(ICharSequence) |
Compares this string to the specified |
ContentEquals(String) |
Compares this string to the specified |
ContentEquals(StringBuffer) |
Compares this string to the specified |
CopyValueOf(Char[]) |
Equivalent to |
CopyValueOf(Char[], Int32, Int32) |
Equivalent to |
Dispose() | (Inherited from Object) |
Dispose(Boolean) | (Inherited from Object) |
EndsWith(String) |
Tests if this string ends with the specified suffix. |
Equals(Object) |
Indicates whether some other object is "equal to" this one. (Inherited from Object) |
EqualsIgnoreCase(String) |
Compares this |
Format(Locale, String, Object[]) |
Returns a formatted string using the specified format string and arguments. |
Format(String, Object[]) |
Returns a formatted string using the specified format string and arguments. |
Formatted(Object[]) | |
GetBytes() |
Encodes this |
GetBytes(Charset) |
Encodes this |
GetBytes(Int32, Int32, Byte[], Int32) |
Obsolete.
Copies characters from this string into the destination byte array. |
GetBytes(String) |
Encodes this |
GetChars(Int32, Int32, Char[], Int32) |
Copies characters from this string into the destination character array. |
GetEnumerator() | |
GetHashCode() |
Returns a hash code value for the object. (Inherited from Object) |
Indent(Int32) |
Adjusts the indentation of each line of this string based on the value of
|
IndexOf(Int32) |
Returns the index within this string of the first occurrence of the specified character. |
IndexOf(Int32, Int32) |
Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index. |
IndexOf(String) |
Returns the index within this string of the first occurrence of the specified substring. |
IndexOf(String, Int32) |
Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. |
Intern() |
Returns a canonical representation for the string object. |
JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
Join(ICharSequence, ICharSequence[]) |
Returns a new String composed of copies of the
|
Join(ICharSequence, IIterable) |
Returns a new |
Join(String, IIterable) |
Returns a new |
Join(String, String[]) |
Returns a new String composed of copies of the
|
LastIndexOf(Int32) |
Returns the index within this string of the last occurrence of the specified character. |
LastIndexOf(Int32, Int32) |
Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index. |
LastIndexOf(String) |
Returns the index within this string of the last occurrence of the specified substring. |
LastIndexOf(String, Int32) |
Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the specified index. |
Length() |
Returns the length of this string. |
Matches(String) |
Tells whether or not this string matches the given regular expression. |
Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
OffsetByCodePoints(Int32, Int32) |
Returns the index within this |
RegionMatches(Boolean, Int32, String, Int32, Int32) |
Tests if two string regions are equal. |
RegionMatches(Int32, String, Int32, Int32) |
Tests if two string regions are equal. |
Repeat(Int32) |
Returns a string whose value is the concatenation of this
string repeated |
Replace(Char, Char) |
Returns a string resulting from replacing all occurrences of
|
Replace(ICharSequence, ICharSequence) |
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. |
Replace(String, String) |
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. |
ReplaceAll(String, String) |
Replaces each substring of this string that matches the given regular expression with the given replacement. |
ReplaceFirst(String, String) |
Replaces the first substring of this string that matches the given regular expression with the given replacement. |
SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
Split(String) |
Splits this string around matches of the given regular expression. |
Split(String, Int32) |
Splits this string around matches of the given regular expression. |
StartsWith(String) |
Tests if this string starts with the specified prefix. |
StartsWith(String, Int32) |
Tests if the substring of this string beginning at the specified index starts with the specified prefix. |
Strip() |
Returns a string whose value is this string, with all leading
and trailing |
StripIndent() |
Returns a string whose value is this string, with incidental Character#isWhitespace(int) white space removed from the beginning and end of every line. |
StripLeading() |
Returns a string whose value is this string, with all leading
|
StripTrailing() |
Returns a string whose value is this string, with all trailing
|
SubSequence(Int32, Int32) |
Returns a character sequence that is a subsequence of this sequence. |
SubSequenceFormatted(Int32, Int32) |
Returns a character sequence that is a subsequence of this sequence. |
Substring(Int32) |
Returns a string that is a substring of this string. |
Substring(Int32, Int32) |
Returns a string that is a substring of this string. |
ToArray<T>() | (Inherited from Object) |
ToCharArray() |
Converts this string to a new character array. |
ToLowerCase() |
Converts all of the characters in this |
ToLowerCase(Locale) |
Converts all of the characters in this |
ToString() | |
ToUpperCase() |
Converts all of the characters in this |
ToUpperCase(Locale) |
Converts all of the characters in this |
Transform(IFunction) |
This method allows the application of a function to |
TranslateEscapes() |
Returns a string whose value is this string, with escape sequences translated as if in a string literal. |
Trim() |
Returns a string whose value is this string, with all leading
and trailing space removed, where space is defined
as any character whose codepoint is less than or equal to
|
UnregisterFromRuntime() | (Inherited from Object) |
ValueOf(Boolean) |
Returns the string representation of the |
ValueOf(Char) |
Returns the string representation of the |
ValueOf(Char[]) |
Returns the string representation of the |
ValueOf(Char[], Int32, Int32) |
Returns the string representation of a specific subarray of the
|
ValueOf(Double) |
Returns the string representation of the |
ValueOf(Int32) |
Returns the string representation of the |
ValueOf(Int64) |
Returns the string representation of the |
ValueOf(Object) |
Returns the string representation of the |
ValueOf(Single) |
Returns the string representation of the |
Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Explicit Interface Implementations
IComparable.CompareTo(Object) | |
IEnumerable.GetEnumerator() | |
IJavaPeerable.Disposed() | (Inherited from Object) |
IJavaPeerable.DisposeUnlessReferenced() | (Inherited from Object) |
IJavaPeerable.Finalized() | (Inherited from Object) |
IJavaPeerable.JniManagedPeerState | (Inherited from Object) |
IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from Object) |
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from Object) |
IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from Object) |
Extension Methods
JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
JavaCast<TResult>(IJavaObject) | |
GetJniTypeName(IJavaPeerable) | |
SubSequence(ICharSequence, Int32, Int32) |