다음을 통해 공유


String Constructors

Definition

Overloads

String()

Creates an empty string.

String(Byte[], Int32, Int32, String)

Constructs a new String by decoding the specified subarray of bytes using the specified charset.

String(Byte[], Int32, Int32, Int32)
Obsolete.

Allocates a new String constructed from a subarray of an array of 8-bit integer values.

String(Int32[], Int32, Int32)

Allocates a new String that contains characters from a subarray of the Unicode code point array argument.

String(Char[], Int32, Int32)

Initializes this string to contain the given chars.

String(Byte[], Int32, Int32)

Constructs a new String by decoding the specified subarray of bytes using the platform's default charset.

String(Byte[], String)

Constructs a new String by decoding the specified array of bytes using the specified java.

String(Byte[], Int32, Int32, Charset)

Constructs a new String by decoding the specified subarray of bytes using the specified java.

String(Byte[], Charset)

Constructs a new String by decoding the specified array of bytes using the specified java.

String(String)

Constructs a new string with the same sequence of characters as toCopy.

String(Char[])

Initializes this string to contain the given chars.

String(Byte[])

Constructs a new String by decoding the specified array of bytes using the platform's default charset.

String(Byte[], Int32)
Obsolete.

Allocates a new String containing characters constructed from an array of 8-bit integer values.

String(StringBuilder)

Allocates a new string that contains the sequence of characters currently contained in the string builder argument.

String(StringBuffer)

Allocates a new string that contains the sequence of characters currently contained in the string buffer argument.

String()

Creates an empty string.

[Android.Runtime.Register(".ctor", "()V", "")]
public String ();
Attributes

Remarks

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.

Applies to

String(Byte[], Int32, Int32, String)

Constructs a new String by decoding the specified subarray of bytes using the specified charset.

[Android.Runtime.Register(".ctor", "([BIILjava/lang/String;)V", "")]
public String (byte[]? bytes, int offset, int length, string charsetName);
[<Android.Runtime.Register(".ctor", "([BIILjava/lang/String;)V", "")>]
new Java.Lang.String : byte[] * int * int * string -> Java.Lang.String

Parameters

bytes
Byte[]

The bytes to be decoded into characters

offset
Int32

The index of the first byte to decode

length
Int32

The number of bytes to decode

charsetName
String

The name of a supported java.nio.charset.Charset charset

Attributes

Exceptions

if data == null.

if byteCount data.length.

if the named charset is not supported.

Remarks

Java documentation for java.lang.String.String(byte[], int, int, 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.

Applies to

String(Byte[], Int32, Int32, Int32)

Caution

deprecated

Allocates a new String constructed from a subarray of an array of 8-bit integer values.

[Android.Runtime.Register(".ctor", "([BIII)V", "")]
[System.Obsolete("deprecated")]
public String (byte[]? ascii, int hibyte, int offset, int count);
[<Android.Runtime.Register(".ctor", "([BIII)V", "")>]
[<System.Obsolete("deprecated")>]
new Java.Lang.String : byte[] * int * int * int -> Java.Lang.String

Parameters

ascii
Byte[]

The bytes to be converted to characters

hibyte
Int32

The top 8 bits of each 16-bit Unicode code unit

offset
Int32

The initial offset

count
Int32

The length

Attributes

Exceptions

if data == null.

if byteCount data.length

Remarks

Allocates a new String constructed from a subarray of an array of 8-bit integer values.

The offset argument is the index of the first byte of the subarray, and the count argument specifies the length of the subarray.

Each byte in the subarray is converted to a char as specified in the #String(byte[],int) String(byte[],int) constructor.

This member is deprecated. This method does not properly convert bytes into characters. As of JDK&nbsp;1.1, the preferred way to do this is via the String constructors that take a java.nio.charset.Charset, charset name, or that use the platform's default charset.

Java documentation for java.lang.String.String(byte[], int, int, int).

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.

Applies to

String(Int32[], Int32, Int32)

Allocates a new String that contains characters from a subarray of the Unicode code point array argument.

[Android.Runtime.Register(".ctor", "([III)V", "")]
public String (int[]? codePoints, int offset, int count);
[<Android.Runtime.Register(".ctor", "([III)V", "")>]
new Java.Lang.String : int[] * int * int -> Java.Lang.String

Parameters

codePoints
Int32[]

Array that is the source of Unicode code points

offset
Int32

The initial offset

count
Int32

The length

Attributes

Exceptions

if codePoints == null.

if any of the elements of codePoints are not valid Unicode code points.

if offset or count are not within the bounds of codePoints.

Remarks

Allocates a new String that contains characters from a subarray of the Unicode code point array argument. The offset argument is the index of the first code point of the subarray and the count argument specifies the length of the subarray. The contents of the subarray are converted to chars; subsequent modification of the int array does not affect the newly created string.

Added in 1.5.

Java documentation for java.lang.String.String(int[], int, int).

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.

Applies to

String(Char[], Int32, Int32)

Initializes this string to contain the given chars.

[Android.Runtime.Register(".ctor", "([CII)V", "")]
public String (char[] data, int offset, int charCount);
[<Android.Runtime.Register(".ctor", "([CII)V", "")>]
new Java.Lang.String : char[] * int * int -> Java.Lang.String

Parameters

data
Char[]
offset
Int32
charCount
Int32
Attributes

Exceptions

if data == null.

if charCount data.length

Remarks

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.

Applies to

String(Byte[], Int32, Int32)

Constructs a new String by decoding the specified subarray of bytes using the platform's default charset.

[Android.Runtime.Register(".ctor", "([BII)V", "")]
public String (byte[]? bytes, int offset, int length);
[<Android.Runtime.Register(".ctor", "([BII)V", "")>]
new Java.Lang.String : byte[] * int * int -> Java.Lang.String

Parameters

bytes
Byte[]

The bytes to be decoded into characters

offset
Int32

The index of the first byte to decode

length
Int32

The number of bytes to decode

Attributes

Exceptions

if data == null.

if byteCount data.length.

Remarks

Constructs a new String by decoding the specified subarray of bytes using the platform's default charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the subarray.

The behavior of this constructor when the given bytes are not valid in the default charset is unspecified. The java.nio.charset.CharsetDecoder class should be used when more control over the decoding process is required.

Added in 1.1.

Java documentation for java.lang.String.String(byte[], int, int).

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.

Applies to

String(Byte[], String)

Constructs a new String by decoding the specified array of bytes using the specified java.

[Android.Runtime.Register(".ctor", "([BLjava/lang/String;)V", "")]
public String (byte[]? bytes, string charsetName);
[<Android.Runtime.Register(".ctor", "([BLjava/lang/String;)V", "")>]
new Java.Lang.String : byte[] * string -> Java.Lang.String

Parameters

bytes
Byte[]

The bytes to be decoded into characters

charsetName
String

The name of a supported java.nio.charset.Charset charset

Attributes

Exceptions

if data == null.

if charsetName is not supported.

Remarks

Constructs a new String by decoding the specified array of bytes using the specified java.nio.charset.Charset charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

The behavior of this constructor when the given bytes are not valid in the given charset is unspecified. The java.nio.charset.CharsetDecoder class should be used when more control over the decoding process is required.

Added in 1.1.

Java documentation for java.lang.String.String(byte[], 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.

Applies to

String(Byte[], Int32, Int32, Charset)

Constructs a new String by decoding the specified subarray of bytes using the specified java.

[Android.Runtime.Register(".ctor", "([BIILjava/nio/charset/Charset;)V", "")]
public String (byte[]? bytes, int offset, int length, Java.Nio.Charset.Charset charset);
[<Android.Runtime.Register(".ctor", "([BIILjava/nio/charset/Charset;)V", "")>]
new Java.Lang.String : byte[] * int * int * Java.Nio.Charset.Charset -> Java.Lang.String

Parameters

bytes
Byte[]

The bytes to be decoded into characters

offset
Int32

The index of the first byte to decode

length
Int32

The number of bytes to decode

charset
Charset

The java.nio.charset.Charset charset to be used to decode the bytes

Attributes

Exceptions

if byteCount data.length

if data == null

Remarks

Constructs a new String by decoding the specified subarray of bytes using the specified java.nio.charset.Charset charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the subarray.

This method always replaces malformed-input and unmappable-character sequences with this charset's default replacement string. The java.nio.charset.CharsetDecoder class should be used when more control over the decoding process is required.

Added in 1.6.

Java documentation for java.lang.String.String(byte[], int, int, java.nio.charset.Charset).

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.

Applies to

String(Byte[], Charset)

Constructs a new String by decoding the specified array of bytes using the specified java.

[Android.Runtime.Register(".ctor", "([BLjava/nio/charset/Charset;)V", "")]
public String (byte[]? bytes, Java.Nio.Charset.Charset charset);
[<Android.Runtime.Register(".ctor", "([BLjava/nio/charset/Charset;)V", "")>]
new Java.Lang.String : byte[] * Java.Nio.Charset.Charset -> Java.Lang.String

Parameters

bytes
Byte[]

The bytes to be decoded into characters

charset
Charset

The java.nio.charset.Charset charset to be used to decode the bytes

Attributes

Exceptions

if data == null

Remarks

Constructs a new String by decoding the specified array of bytes using the specified java.nio.charset.Charset charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

This method always replaces malformed-input and unmappable-character sequences with this charset's default replacement string. The java.nio.charset.CharsetDecoder class should be used when more control over the decoding process is required.

Added in 1.6.

Java documentation for java.lang.String.String(byte[], java.nio.charset.Charset).

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.

Applies to

String(String)

Constructs a new string with the same sequence of characters as toCopy.

[Android.Runtime.Register(".ctor", "(Ljava/lang/String;)V", "")]
public String (string toCopy);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/String;)V", "")>]
new Java.Lang.String : string -> Java.Lang.String

Parameters

toCopy
String
Attributes

Remarks

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.

Applies to

String(Char[])

Initializes this string to contain the given chars.

[Android.Runtime.Register(".ctor", "([C)V", "")]
public String (char[] data);
[<Android.Runtime.Register(".ctor", "([C)V", "")>]
new Java.Lang.String : char[] -> Java.Lang.String

Parameters

data
Char[]
Attributes

Exceptions

if data == null

Remarks

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.

Applies to

String(Byte[])

Constructs a new String by decoding the specified array of bytes using the platform's default charset.

[Android.Runtime.Register(".ctor", "([B)V", "")]
public String (byte[]? bytes);
[<Android.Runtime.Register(".ctor", "([B)V", "")>]
new Java.Lang.String : byte[] -> Java.Lang.String

Parameters

bytes
Byte[]

The bytes to be decoded into characters

Attributes

Remarks

Constructs a new String by decoding the specified array of bytes using the platform's default charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

The behavior of this constructor when the given bytes are not valid in the default charset is unspecified. The java.nio.charset.CharsetDecoder class should be used when more control over the decoding process is required.

Added in 1.1.

Java documentation for java.lang.String.String(byte[]).

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.

Applies to

String(Byte[], Int32)

Caution

deprecated

Allocates a new String containing characters constructed from an array of 8-bit integer values.

[Android.Runtime.Register(".ctor", "([BI)V", "")]
[System.Obsolete("deprecated")]
public String (byte[]? ascii, int hibyte);
[<Android.Runtime.Register(".ctor", "([BI)V", "")>]
[<System.Obsolete("deprecated")>]
new Java.Lang.String : byte[] * int -> Java.Lang.String

Parameters

ascii
Byte[]

The bytes to be converted to characters

hibyte
Int32

The top 8 bits of each 16-bit Unicode code unit

Attributes

Exceptions

if data == null.

Remarks

Allocates a new String containing characters constructed from an array of 8-bit integer values. Each character c in the resulting string is constructed from the corresponding component b in the byte array such that:

<blockquote>

<b><i>c</i></b> == (char)(((hibyte &amp; 0xff) &lt;&lt; 8)
                                    | (<b><i>b</i></b> &amp; 0xff))

</blockquote>

This member is deprecated. This method does not properly convert bytes into characters. As of JDK&nbsp;1.1, the preferred way to do this is via the String constructors that take a java.nio.charset.Charset, charset name, or that use the platform's default charset.

Java documentation for java.lang.String.String(byte[], int).

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.

Applies to

String(StringBuilder)

Allocates a new string that contains the sequence of characters currently contained in the string builder argument.

[Android.Runtime.Register(".ctor", "(Ljava/lang/StringBuilder;)V", "")]
public String (Java.Lang.StringBuilder builder);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/StringBuilder;)V", "")>]
new Java.Lang.String : Java.Lang.StringBuilder -> Java.Lang.String

Parameters

builder
StringBuilder

A StringBuilder

Attributes

Exceptions

if stringBuilder == null.

Remarks

Allocates a new string that contains the sequence of characters currently contained in the string builder argument. The contents of the string builder are copied; subsequent modification of the string builder does not affect the newly created string.

This constructor is provided to ease migration to StringBuilder. Obtaining a string from a string builder via the toString method is likely to run faster and is generally preferred.

Added in 1.5.

Java documentation for java.lang.String.String(java.lang.StringBuilder).

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.

Applies to

String(StringBuffer)

Allocates a new string that contains the sequence of characters currently contained in the string buffer argument.

[Android.Runtime.Register(".ctor", "(Ljava/lang/StringBuffer;)V", "")]
public String (Java.Lang.StringBuffer buffer);
[<Android.Runtime.Register(".ctor", "(Ljava/lang/StringBuffer;)V", "")>]
new Java.Lang.String : Java.Lang.StringBuffer -> Java.Lang.String

Parameters

buffer
StringBuffer

A StringBuffer

Attributes

Remarks

Allocates a new string that contains the sequence of characters currently contained in the string buffer argument. The contents of the string buffer are copied; subsequent modification of the string buffer does not affect the newly created string.

Java documentation for java.lang.String.String(java.lang.StringBuffer).

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.

Applies to