📄 string.html
字号:
int dstBegin)</PRE><DL><DD><B>Deprecated.</B> <I>This method does not properly convert characters into bytes. As of JDK 1.1, the preferred way to do this is via the <code>getBytes(String enc)</code> method, which takes a character-encoding name, or the <code>getBytes()</code> method, which uses the platform's default encoding.</I><P><DD>Copies characters from this string into the destination byte array. Each byte receives the 8 low-order bits of the corresponding character. The eight high-order bits of each character are not copied and do not participate in the transfer in any way. <p> The first character to be copied is at index <code>srcBegin</code>; the last character to be copied is at index <code>srcEnd-1</code>. The total number of characters to be copied is <code>srcEnd-srcBegin</code>. The characters, converted to bytes, are copied into the subarray of <code>dst</code> starting at index <code>dstBegin</code> and ending at index: <p><blockquote><pre> dstbegin + (srcEnd-srcBegin) - 1 </pre></blockquote><DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>srcBegin</CODE> - index of the first character in the string to copy.<DD><CODE>srcEnd</CODE> - index after the last character in the string to copy.<DD><CODE>dst</CODE> - the destination array.<DD><CODE>dstBegin</CODE> - the start offset in the destination array.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/IndexOutOfBoundsException.html">IndexOutOfBoundsException</A></CODE> - if any of the following is true: <ul<li><code>srcBegin</code> is negative <li><code>srcBegin</code> is greater than <code>srcEnd</code> <li><code>srcEnd</code> is greater than the length of this String <li><code>dstBegin</code> is negative <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than <code>dst.length</code><DD><CODE><A HREF="../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if <code>dst</code> is <code>null</code></DL></DD></DL><HR><A NAME="getBytes(java.lang.String)"><!-- --></A><H3>getBytes</H3><PRE>public byte[] <B>getBytes</B>(<A HREF="../../java/lang/String.html">String</A> enc) throws <A HREF="../../java/io/UnsupportedEncodingException.html">UnsupportedEncodingException</A></PRE><DL><DD>Convert this <code>String</code> into bytes according to the specified character encoding, storing the result into a new byte array.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>enc</CODE> - The name of a supported <a href="package-summary.html#charenc">character encoding</a><DT><B>Returns:</B><DD>The resultant byte array<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/UnsupportedEncodingException.html">UnsupportedEncodingException</A></CODE> - If the named encoding is not supported<DT><B>Since: </B><DD>JDK1.1</DD></DL></DD></DL><HR><A NAME="getBytes()"><!-- --></A><H3>getBytes</H3><PRE>public byte[] <B>getBytes</B>()</PRE><DL><DD>Convert this <code>String</code> into bytes according to the platform's default character encoding, storing the result into a new byte array.<DD><DL></DL></DD><DD><DL><DT><B>Returns:</B><DD>the resultant byte array.<DT><B>Since: </B><DD>JDK1.1</DD></DL></DD></DL><HR><A NAME="equals(java.lang.Object)"><!-- --></A><H3>equals</H3><PRE>public boolean <B>equals</B>(<A HREF="../../java/lang/Object.html">Object</A> anObject)</PRE><DL><DD>Compares this string to the specified object. The result is <code>true</code> if and only if the argument is not <code>null</code> and is a <code>String</code> object that represents the same sequence of characters as this object.<DD><DL><DT><B>Overrides:</B><DD><CODE><A HREF="../../java/lang/Object.html#equals(java.lang.Object)">equals</A></CODE> in class <CODE><A HREF="../../java/lang/Object.html">Object</A></CODE></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>anObject</CODE> - the object to compare this <code>String</code> against.<DT><B>Returns:</B><DD><code>true</code> if the <code>String </code>are equal; <code>false</code> otherwise.<DT><B>See Also: </B><DD><A HREF="../../java/lang/String.html#compareTo(java.lang.String)"><CODE>compareTo(java.lang.String)</CODE></A>, <A HREF="../../java/lang/String.html#equalsIgnoreCase(java.lang.String)"><CODE>equalsIgnoreCase(java.lang.String)</CODE></A></DL></DD></DL><HR><A NAME="equalsIgnoreCase(java.lang.String)"><!-- --></A><H3>equalsIgnoreCase</H3><PRE>public boolean <B>equalsIgnoreCase</B>(<A HREF="../../java/lang/String.html">String</A> anotherString)</PRE><DL><DD>Compares this <code>String</code> to another <code>String</code>, ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length, and corresponding characters in the two strings are equal ignoring case. <p> Two characters <code>c1</code> and <code>c2</code> are considered the same, ignoring case if at least one of the following is true: <ul><li>The two characters are the same (as compared by the <code>==</code> operator). <li>Applying the method <A HREF="../../java/lang/Character.html#toUpperCase(char)"><CODE>Character.toUpperCase(char)</CODE></A> to each character produces the same result. <li>Applying the method <A HREF="../../java/lang/Character.html#toLowerCase(char)"><CODE>Character.toLowerCase(char)</CODE></A> to each character produces the same result.</ul><DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>anotherString</CODE> - the <code>String</code> to compare this <code>String</code> against.<DT><B>Returns:</B><DD><code>true</code> if the argument is not <code>null</code> and the <code>String</code>s are equal, ignoring case; <code>false</code> otherwise.<DT><B>See Also: </B><DD><A HREF="../../java/lang/String.html#equals(java.lang.Object)"><CODE>equals(Object)</CODE></A>, <A HREF="../../java/lang/Character.html#toLowerCase(char)"><CODE>Character.toLowerCase(char)</CODE></A>, <A HREF="../../java/lang/Character.html#toUpperCase(char)"><CODE>Character.toUpperCase(char)</CODE></A></DL></DD></DL><HR><A NAME="compareTo(java.lang.String)"><!-- --></A><H3>compareTo</H3><PRE>public int <B>compareTo</B>(<A HREF="../../java/lang/String.html">String</A> anotherString)</PRE><DL><DD>Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this <code>String</code> object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer if this <code>String</code> object lexicographically precedes the argument string. The result is a positive integer if this <code>String</code> object lexicographically follows the argument string. The result is zero if the strings are equal; <code>compareTo</code> returns <code>0</code> exactly when the <A HREF="../../java/lang/String.html#equals(java.lang.Object)"><CODE>equals(Object)</CODE></A> method would return <code>true</code>. <p> This is the definition of lexicographic ordering. If two strings are different, then either they have different characters at some index that is a valid index for both strings, or their lengths are different, or both. If they have different characters at one or more index positions, let <i>k</i> be the smallest such index; then the string whose character at position <i>k</i> has the smaller value, as determined by using the < operator, lexicographically precedes the other string. In this case, <code>compareTo</code> returns the difference of the two character values at position <code>k</code> in the two string -- that is, the value: <blockquote><pre> this.charAt(k)-anotherString.charAt(k) </pre></blockquote> If there is no index position at which they differ, then the shorter string lexicographically precedes the longer string. In this case, <code>compareTo</code> returns the difference of the lengths of the strings -- that is, the value: <blockquote><pre> this.length()-anotherString.length() </pre></blockquote><DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>anotherString</CODE> - the <code>String</code> to be compared.<DT><B>Returns:</B><DD>the value <code>0</code> if the argument string is equal to this string; a value less than <code>0</code> if this string is lexicographically less than the string argument; and a value greater than <code>0</code> if this string is lexicographically greater than the string argument.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if <code>anotherString</code> is <code>null</code>.</DL></DD></DL><HR><A NAME="compareTo(java.lang.Object)"><!-- --></A><H3>compareTo</H3><PRE>public int <B>compareTo</B>(<A HREF="../../java/lang/Object.html">Object</A> o)</PRE><DL><DD>Compares this String to another Object. If the Object is a String, this function behaves like <code>compareTo(String)</code>. Otherwise, it throws a <code>ClassCastException</code> (as Strings are comparable only to other Strings).<DD><DL><DT><B>Specified by: </B><DD><CODE><A HREF="../../java/lang/Comparable.html#compareTo(java.lang.Object)">compareTo</A></CODE> in interface <CODE><A HREF="../../java/lang/Comparable.html">Comparable</A></CODE></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>o</CODE> - the <code>Object</code> to be compared.<DT><B>Returns:</B><DD>the value <code>0</code> if the argument is a string lexicographically equal to this string; a value less than <code>0</code> if the argument is a string lexicographically greater than this string; and a value greater than <code>0</code> if the argument is a string lexicographically less than this string.<DT><B>Throws:</B><DD><CODE><code>ClassCastException</code></CODE> - if the argument is not a <code>String</code>.<DT><B>Since: </B><DD>1.2</DD><DT><B>See Also: </B><DD><A HREF="../../java/lang/Comparable.html"><CODE>Comparable</CODE></A></DL></DD></DL><HR><A NAME="compareToIgnoreCase(java.lang.String)"><!-- --></A><H3>compareToIgnoreCase</H3><PRE>public int <B>compareToIgnoreCase</B>(<A HREF="../../java/lang/String.html">String</A> str)</PRE><DL><DD>Compares two strings lexicographically, ignoring case considerations. This method returns an integer whose sign is that of <code>this.toUpperCase().toLowerCase().compareTo( str.toUpperCase().toLowerCase())</code>. <p> Note that this method does <em>not</em> take locale into account, and will result in an unsatisfactory ordering for certain locales. The java.text package provides <em>collators</em> to allow locale-sensitive ordering.<DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>str</CODE> - the <code>String</code> to be compared.<DT><B>Returns:</B><DD>a negative integer, zero, or a positive integer as the the specified String is greater than, equal to, or less than this String, ignoring case considerations.<DT><B>Since: </B><DD>1.2</DD><DT><B>See Also: </B><DD><A HREF="../../java/text/Collator.html#compare(java.lang.String, java.lang.String)"><CODE>Collator.compare(String, String)</CODE></A></DL></DD></DL><HR><A NAME="regionMatches(int, java.lang.String, int, int)"><!-- --></A><H3>regionMatches</H3><PRE>public boolean <B>regionMatches</B>(int toffset, <A HREF="../../java/lang/String.html">String</A> other, int ooffset, int len)</PRE><DL><DD>Tests if two string regions are equal. <p> A substring of this <tt>String</tt> object is compared to a substring of the argument other. The result is true if these substrings represent identical character sequences. The substring of this <tt>String</tt> object to be compared begins at index <tt>toffset</tt> and has length <tt>len</tt>. The substring of other to be compared begins at index <tt>ooffset</tt> and has length <tt>len</tt>. The result is <tt>false</tt> if and only if at least one of the following is true: <ul><li><tt>toffset</tt> is negative. <li><tt>ooffset</tt> is negative. <li><tt>toffset+len</tt> is greater than the length of this <tt>String</tt> object. <li><tt>ooffset+len</tt> is greater than the length of the other argument. <li>There is some nonnegative integer <i>k</i> less than <tt>len</tt> such that: <tt>this.charAt(toffset+<i>k</i>) != other.charAt(ooffset+<i>k</i>)</tt> </u><DD><DL></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>toffset</CODE> - the starting offset of the subregion in this string.<DD><CODE>other</CODE> - the string argument.<DD><CODE>ooffset</CODE> - the starting offset of the subregion in the string argument.<DD><CODE>len</CODE> - the number of characters to compare.<DT><B>Returns:</B><DD><code>true</code> if the specified subregion of this string exactly matches the specified subregion of the string argument; <code>false</code> otherwise.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/lang/NullPointerException.html">NullPointerException</A></CODE> - if <tt>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -