📄 string.html
字号:
<A NAME="indexOf(java.lang.String)"><!-- --></A><H3>
indexOf</H3>
<PRE>
public int <B>indexOf</B>(<A HREF="../../java/lang/String.html">String</A> str)</PRE>
<DL>
<DD>Returns the index within this string of the first occurrence of the specified substring. The integer returned is the smallest value <i>k</i> such that: <blockquote><pre> this.startsWith(str, <i>k</i>) </pre></blockquote> is <code>true</code>.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>str</CODE> - any string.<DT><B>Returns:</B><DD>if the string argument occurs as a substring within this object, then the index of the first character of the first such substring is returned; if it does not occur as a substring, <code>-1</code> is returned.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if <code>str</code> is <code>null</code>.</DL>
</DD>
</DL>
<HR>
<A NAME="indexOf(java.lang.String, int)"><!-- --></A><H3>
indexOf</H3>
<PRE>
public int <B>indexOf</B>(<A HREF="../../java/lang/String.html">String</A> str, int fromIndex)</PRE>
<DL>
<DD>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 <i>k</i> such that: <blockquote><pre> this.startsWith(str, <i>k</i>) && (<i>k</i> >= fromIndex) </pre></blockquote> is <code>true</code>. <p> There is no restriction on the value of <code>fromIndex</code>. 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: <code>-1</code> is returned.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>str</CODE> - the substring to search for.<DD><CODE>fromIndex</CODE> - the index to start the search from.<DT><B>Returns:</B><DD>If the string argument occurs as a substring within this object at a starting index no smaller than <code>fromIndex</code>, then the index of the first character of the first such substring is returned. If it does not occur as a substring starting at <code>fromIndex</code> or beyond, <code>-1</code> is returned.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if <code>str</code> is <code>null</code></DL>
</DD>
</DL>
<HR>
<A NAME="substring(int)"><!-- --></A><H3>
substring</H3>
<PRE>
public <A HREF="../../java/lang/String.html">String</A> <B>substring</B>(int beginIndex)</PRE>
<DL>
<DD>Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string. <p> Examples: <blockquote><pre> "unhappy".substring(2) returns "happy" "Harbison".substring(3) returns "bison" "emptiness".substring(9) returns "" (an empty string) </pre></blockquote><DD><DL>
<DT><B>Parameters:</B><DD><CODE>beginIndex</CODE> - the beginning index, inclusive.<DT><B>Returns:</B><DD>the specified substring.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/IndexOutOfBoundsException.html">IndexOutOfBoundsException</A></CODE> - if <code>beginIndex</code> is negative or larger than the length of this <code>String</code> object.</DL>
</DD>
</DL>
<HR>
<A NAME="substring(int, int)"><!-- --></A><H3>
substring</H3>
<PRE>
public <A HREF="../../java/lang/String.html">String</A> <B>substring</B>(int beginIndex, int endIndex)</PRE>
<DL>
<DD>Returns a new string that is a substring of this string. The substring begins at the specified <code>beginIndex</code> and extends to the character at index <code>endIndex - 1</code>. Thus the length of the substring is <code>endIndex-beginIndex</code>. <p> Examples: <blockquote><pre> "hamburger".substring(4, 8) returns "urge" "smiles".substring(1, 5) returns "mile" </pre></blockquote><DD><DL>
<DT><B>Parameters:</B><DD><CODE>beginIndex</CODE> - the beginning index, inclusive.<DD><CODE>endIndex</CODE> - the ending index, exclusive.<DT><B>Returns:</B><DD>the specified substring.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/IndexOutOfBoundsException.html">IndexOutOfBoundsException</A></CODE> - if the <code>beginIndex</code> is negative, or <code>endIndex</code> is larger than the length of this <code>String</code> object, or <code>beginIndex</code> is larger than <code>endIndex</code>.</DL>
</DD>
</DL>
<HR>
<A NAME="concat(java.lang.String)"><!-- --></A><H3>
concat</H3>
<PRE>
public <A HREF="../../java/lang/String.html">String</A> <B>concat</B>(<A HREF="../../java/lang/String.html">String</A> str)</PRE>
<DL>
<DD>Concatenates the specified string to the end of this string. <p> If the length of the argument string is <code>0</code>, then this <code>String</code> object is returned. Otherwise, a new <code>String</code> object is created, representing a character sequence that is the concatenation of the character sequence represented by this <code>String</code> object and the character sequence represented by the argument string.<p> Examples: <blockquote><pre> "cares".concat("s") returns "caress" "to".concat("get").concat("her") returns "together" </pre></blockquote><DD><DL>
<DT><B>Parameters:</B><DD><CODE>str</CODE> - the <code>String</code> that is concatenated to the end of this <code>String</code>.<DT><B>Returns:</B><DD>a string that represents the concatenation of this object's characters followed by the string argument's characters.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if <code>str</code> is <code>null</code>.</DL>
</DD>
</DL>
<HR>
<A NAME="replace(char, char)"><!-- --></A><H3>
replace</H3>
<PRE>
public <A HREF="../../java/lang/String.html">String</A> <B>replace</B>(char oldChar, char newChar)</PRE>
<DL>
<DD>Returns a new string resulting from replacing all occurrences of <code>oldChar</code> in this string with <code>newChar</code>. <p> If the character <code>oldChar</code> does not occur in the character sequence represented by this <code>String</code> object, then a reference to this <code>String</code> object is returned. Otherwise, a new <code>String</code> object is created that represents a character sequence identical to the character sequence represented by this <code>String</code> object, except that every occurrence of <code>oldChar</code> is replaced by an occurrence of <code>newChar</code>. <p> Examples: <blockquote><pre> "mesquite in your cellar".replace('e', 'o') returns "mosquito in your collar" "the war of baronets".replace('r', 'y') returns "the way of bayonets" "sparring with a purple porpoise".replace('p', 't') returns "starring with a turtle tortoise" "JonL".replace('q', 'x') returns "JonL" (no change) </pre></blockquote><DD><DL>
<DT><B>Parameters:</B><DD><CODE>oldChar</CODE> - the old character.<DD><CODE>newChar</CODE> - the new character.<DT><B>Returns:</B><DD>a string derived from this string by replacing every occurrence of <code>oldChar</code> with <code>newChar</code>.</DL>
</DD>
</DL>
<HR>
<A NAME="toLowerCase()"><!-- --></A><H3>
toLowerCase</H3>
<PRE>
public <A HREF="../../java/lang/String.html">String</A> <B>toLowerCase</B>()</PRE>
<DL>
<DD>Converts all of the characters in this String to lower case.<DD><DL>
<DT><B>Returns:</B><DD>the String, converted to lowercase.<DT><B>See Also: </B><DD><A HREF="../../java/lang/Character.html#toLowerCase(char)"><CODE>Character.toLowerCase(char)</CODE></A>,
<A HREF="../../java/lang/String.html#toUpperCase()"><CODE>toUpperCase()</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="toUpperCase()"><!-- --></A><H3>
toUpperCase</H3>
<PRE>
public <A HREF="../../java/lang/String.html">String</A> <B>toUpperCase</B>()</PRE>
<DL>
<DD>Converts all of the characters in this String to upper case.<DD><DL>
<DT><B>Returns:</B><DD>the String, converted to uppercase.<DT><B>See Also: </B><DD><A HREF="../../java/lang/Character.html#toLowerCase(char)"><CODE>Character.toLowerCase(char)</CODE></A>,
<A HREF="../../java/lang/String.html#toUpperCase()"><CODE>toUpperCase()</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="trim()"><!-- --></A><H3>
trim</H3>
<PRE>
public <A HREF="../../java/lang/String.html">String</A> <B>trim</B>()</PRE>
<DL>
<DD>Removes white space from both ends of this string. <p> If this <code>String</code> object represents an empty character sequence, or the first and last characters of character sequence represented by this <code>String</code> object both have codes greater than <code>'\u0020'</code> (the space character), then a reference to this <code>String</code> object is returned. <p> Otherwise, if there is no character with a code greater than <code>'\u0020'</code> in the string, then a new <code>String</code> object representing an empty string is created and returned. <p> Otherwise, let <i>k</i> be the index of the first character in the string whose code is greater than <code>'\u0020'</code>, and let <i>m</i> be the index of the last character in the string whose code is greater than <code>'\u0020'</code>. A new <code>String</code> object is created, representing the substring of this string that begins with the character at index <i>k</i> and ends with the character at index <i>m</i>-that is, the result of <code>this.substring(<i>k</i>, <i>m</i>+1)</code>. <p> This method may be used to trim whitespace from the beginning and end of a string; in fact, it trims all ASCII control characters as well.<DD><DL>
<DT><B>Returns:</B><DD>this string, with white space removed from the front and end.</DL>
</DD>
</DL>
<HR>
<A NAME="toString()"><!-- --></A><H3>
toString</H3>
<PRE>
public <A HREF="../../java/lang/String.html">String</A> <B>toString</B>()</PRE>
<DL>
<DD>This object (which is already a string!) is itself returned.<DD><DL>
<DT><B>Overrides:</B><DD><CODE><A HREF="../../java/lang/Object.html#toString()">toString</A></CODE> in class <CODE><A HREF="../../java/lang/Object.html">Object</A></CODE></DL>
</DD>
<DD><DL>
<DT><B>Returns:</B><DD>the string itself.</DL>
</DD>
</DL>
<HR>
<A NAME="toCharArray()"><!-- --></A><H3>
toCharArray</H3>
<PRE>
public char[] <B>toCharArray</B>()</PRE>
<DL>
<DD>Converts this string to a new character array.<DD><DL>
<DT><B>Returns:</B><DD>a newly allocated character array whose length is the length of this string and whose contents are initialized to contain the character sequence represented by this string.</DL>
</DD>
</DL>
<HR>
<A NAME="valueOf(java.lang.Object)"><!-- --></A><H3>
valueOf</H3>
<PRE>
public static <A HREF="../../java/lang/String.html">String</A> <B>valueOf</B>(<A HREF="../../java/lang/Object.html">Object</A> obj)</PRE>
<DL>
<DD>Returns the string representation of the <code>Object</code> argument.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>obj</CODE> - an <code>Object</code>.<DT><B>Returns:</B><DD>if the argument is <code>null</code>, then a string equal to <code>"null"</code>; otherwise, the value of <code>obj.toString()</code> is returned.<DT><B>See Also: </B><DD><A HREF="../../java/lang/Object.html#toString()"><CODE>Object.toString()</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="valueOf(char[])"><!-- --></A><H3>
valueOf</H3>
<PRE>
public static <A HREF="../../java/lang/String.html">String</A> <B>valueOf</B>(char[] data)</PRE>
<DL>
<DD>Returns the string representation of the <code>char</code> array argument. The contents of the character array are copied; subsequent modification of the character array does not affect the newly created string.<DD><DL>
<DT><B>Parameters:</B><DD><CODE>data</CODE> - a <code>char</code> array.<DT><B>Returns:</B><DD>a newly allocated string representing the same sequence of characters contained in the character array argument.</DL>
</DD>
</DL>
<HR>
<A NAME="valueOf(char[],
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -