Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class String
- Object
- String
ImplementsCharSequence, Comparable<String>
char[]), StringBuffer.append(char[], int, int), StringBuffer.append(int), StringBuffer.append(long), StringBuffer.append(java.lang.Object), StringBuffer.append(java.lang.String)Fields
public static final Comparator<String> CASE_INSENSITIVE_ORDER |
Constructors
public String() | Initializes a newly created String object so that it represents an empty character sequence. |
public String(byte[] bytes) | Construct a new String by converting the specified array of bytes using the platform’s default character encoding. |
public String(byte[] bytes, int off, int len) | Construct a new String by converting the specified subarray of bytes using the platform’s default character encoding. |
public String(byte[] bytes, int off, int len, String enc)
throws UnsupportedEncodingException | Construct a new String by converting the specified subarray of bytes using the specified character encoding. |
public String(byte[] bytes, Charset charset) | Construct a new String by converting the specified array of bytes using the specified character encoding. |
public String(byte[] bytes, String enc)
throws UnsupportedEncodingException | Construct a new String by converting the specified array of bytes using the specified character encoding. |
public String(char[] value) | Allocates a new String so that it represents the sequence of characters currently contained in the character array argument. |
public String(char[] value, int offset, int count) | Allocates a new String that contains characters from a subarray of the character array argument. |
public String(String value) | Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. |
public String(StringBuffer buffer) | Allocates a new string that contains the sequence of characters currently contained in the string buffer argument. |
public String(StringBuilder buffer) | |
public String(int[] codePoints, int offset, int count) | A string of the code points codePoints[offset] to codePoints[offset + count - 1]. |
public String(byte[] bytes, int offset, int length, Charset charset) | Decodes length bytes of bytes from offset with charset. |
Methods
Inherited methods
From CharSequence
Field details
CASE_INSENSITIVE_ORDER
public static final Comparator<String> CASE_INSENSITIVE_ORDERConstructor details
String
public String()String
public String(byte[] bytes)String
public String(byte[] bytes, int off, int len)String
public String(byte[] bytes, int off, int len, String enc)
throws UnsupportedEncodingExceptionConstruct a new String by converting the specified subarray of bytes using the specified character encoding. The length of the new String is a function of the encoding, and hence may not be equal to the length of the subarray. bytes - The bytes to be converted into charactersoff - Index of the first byte to convertlen - Number of bytes to convertenc - The name of a character encoding
- If the named encoding is not supported JDK1.1
String
public String(byte[] bytes, Charset charset)String
public String(byte[] bytes, String enc)
throws UnsupportedEncodingExceptionConstruct a new String by converting the specified array of bytes using the specified character encoding. The length of the new String is a function of the encoding, and hence may not be equal to the length of the byte array. bytes - The bytes to be converted into charactersenc - The name of a supported character encoding
- If the named encoding is not supported JDK1.1
String
public String(char[] value)Allocates a new String so that it represents the sequence of characters currently contained in the character array argument. The contents of the character array are copied; subsequent modification of the character array does not affect the newly created string. value - the initial value of the string.
- if value is null.
String
public String(char[] value, int offset, int count)Allocates a new String that contains characters from a subarray of the character array argument. The offset argument is the index of the first character of the subarray and the count argument specifies the length of the subarray. The contents of the subarray are copied; subsequent modification of the character array does not affect the newly created string. value - array that is the source of characters.offset - the initial offset.count - the length.
- if the offset and count arguments index characters outside the bounds of the value array.
- if value is null.
String
public String(String value)String
public String(StringBuffer buffer)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. buffer - a StringBuffer.
- If buffer is null.
String
public String(StringBuilder buffer)String
public String(int[] codePoints, int offset, int count)codePoints[offset] to
codePoints[offset + count - 1].String
public String(byte[] bytes, int offset, int length, Charset charset)length bytes of bytes from offset with charset.Method details
charAt
public char charAt(int index)Parameters
indexint- the index of the character to return.
Returns
Throws
IndexOutOfBoundsException- if
index < 0orindexis greater than the length of this sequence.
compareTo
public int compareTo(String anotherString)Parameters
anotherStringString- the object to compare to this instance.
Returns
another;
a positive integer if this instance is greater than
another; 0 if this instance has the same order as
another.Throws
ClassCastException- if
anothercannot be converted into something comparable tothisinstance.
compareToIgnoreCase
public int compareToIgnoreCase(String anotherString)contentEquals
public boolean contentEquals(CharSequence cs)contentEquals
public boolean contentEquals(StringBuffer sb)copyValueOf
public static String copyValueOf(char[] data)copyValueOf
public static String copyValueOf(char[] data, int offset, int count)concat
public String concat(String str)endsWith
public boolean endsWith(String suffix)equals
public boolean equals(Object anObject)equalsIgnoreCase
public boolean equalsIgnoreCase(String anotherString)getBytes
public byte[] getBytes()getBytes
public byte[] getBytes(String enc)
throws UnsupportedEncodingExceptiongetBytes
public byte[] getBytes(Charset charset)getBytes(String), this throws no checked exception.getChars
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)hashCode
public int hashCode()s[0]*31^(n-1) + s[1]*31^(n-2) + … + s[n-1] using int arithmetic, where s[i] is the
th character of the string, n is the length of the string, and ^ indicates exponentiation. (The hash value of the empty string is zero.)indexOf
public int indexOf(int ch)indexOf
public int indexOf(int ch, int fromIndex)Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index. If a character with value ch occurs in the character sequence represented by this String object at an index no smaller than fromIndex, then the index of the first such occurrence is returned–that is, the smallest value k such that: (this.charAt( ) == ch) && (
= fromIndex) is true. If no such character occurs in this string at or after position fromIndex, then -1 is returned. There is no restriction on the value of fromIndex. If it is negative, it has the same effect as if it were zero: this entire string may be searched. If it is greater than the length of this string, it has the same effect as if it were equal to the length of this string: -1 is returned.
indexOf
public int indexOf(String str)indexOf
public int indexOf(String str, int fromIndex)Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. The integer returned is the smallest value such that: this.startsWith(str, ) && (
= fromIndex) is true. There is no restriction on the value of fromIndex. If it is negative, it has the same effect as if it were zero: this entire string may be searched. If it is greater than the length of this string, it has the same effect as if it were equal to the length of this string: -1 is returned.
intern
public String intern()lastIndexOf
public int lastIndexOf(int ch)lastIndexOf
public int lastIndexOf(int ch, int fromIndex)lastIndexOf
public int lastIndexOf(String string)Parameters
stringString- the string to find.
Returns
Throws
NullPointerException- if
stringisnull.
lastIndexOf
public int lastIndexOf(String subString, int start)Parameters
subStringString- the string to find.
startint- the starting offset.
Returns
Throws
NullPointerException- if
subStringisnull.
length
public int length()Returns
regionMatches
public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)replace
public String replace(char oldChar, char newChar)replace
public String replace(CharSequence target, CharSequence replacement)startsWith
public boolean startsWith(String prefix)startsWith
public boolean startsWith(String prefix, int toffset)substring
public String substring(int beginIndex)substring
public String substring(int beginIndex, int endIndex)toCharArray
public char[] toCharArray()toLowerCase
public String toLowerCase()toString
public String toString()toUpperCase
public String toUpperCase()toUpperCase
public String toUpperCase(Locale locale)trim
public String trim()valueOf
public static String valueOf(boolean b)valueOf
public static String valueOf(char c)valueOf
public static String valueOf(char[] data)valueOf
public static String valueOf(char[] data, int offset, int count)valueOf
public static String valueOf(double d)valueOf
public static String valueOf(float f)valueOf
public static String valueOf(int i)valueOf
public static String valueOf(long l)valueOf
public static String valueOf(Object obj)subSequence
public CharSequence subSequence(int start, int end)CharSequence from the start index (inclusive)
to the end index (exclusive) of this sequence.Parameters
startint- the start offset of the sub-sequence. It is inclusive, that is, the index of the first character that is included in the sub-sequence.
endint- the end offset of the sub-sequence. It is exclusive, that is, the index of the first character after those that are included in the sub-sequence
Returns
Throws
IndexOutOfBoundsException- if
start end, or ifstartorendare greater than the length of this sequence.
format
public static String format(String format, Object... args)contains
public boolean contains(CharSequence seq)Parameters
seqCharSequence- The charsequence to check
Returns
isEmpty
public boolean isEmpty()Returns
regionMatches
public boolean regionMatches(int thisStart, String string, int start, int length)Parameters
thisStartint- the starting offset in this string.
stringString- the string to compare.
startint- the starting offset in the specified string.
lengthint- the number of characters to compare.
Returns
true if the ranges of characters are equal, false
otherwiseThrows
NullPointerException- if
stringisnull.
codePointAt
public int codePointAt(int index)index.codePointBefore
public int codePointBefore(int index)index.codePointCount
public int codePointCount(int beginIndex, int endIndex)beginIndex and endIndex.offsetByCodePoints
public int offsetByCodePoints(int index, int codePointOffset)codePointOffset code points away from index.indexOf
public int indexOf(int ch, int beginIndex, int endIndex)ch in [beginIndex, endIndex), or -1.indexOf
public int indexOf(String str, int beginIndex, int endIndex)str that lies wholly in [beginIndex, endIndex), or -1.join
public static String join(CharSequence delimiter, CharSequence... elements)delimiter between every two.join
public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements)delimiter between every two.format
public static String format(Locale l, String format, Object... args)format(String, Object...).toLowerCase
public String toLowerCase(Locale locale)toLowerCase().formatted
public String formatted(Object... args)String.format(this, args).isBlank
public boolean isBlank()strip
public String strip()stripLeading
public String stripLeading()stripTrailing
public String stripTrailing()repeat
public String repeat(int count)count times over.lines
public Stream<String> lines()indent
public String indent(int n)n spaces, or outdented for a negative n.stripIndent
public String stripIndent()translateEscapes
public String translateEscapes()transform
public <R> R transform(Function<? super String, ? extends R> f)f.apply(this).