⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
  {    return toUpperCase(Locale.getDefault());  }  /**   * Trims all characters less than or equal to <code>'\u0020'</code>   * (<code>' '</code>) from the beginning and end of this String. This   * includes many, but not all, ASCII control characters, and all   * {@link Character#isWhitespace(char)}.   *   * @return new trimmed String, or this if nothing trimmed   */  public String trim()  {    int limit = count + offset;    if (count == 0 || (value[offset] > '\u0020'                       && value[limit - 1] > '\u0020'))      return this;    int begin = offset;    do      if (begin == limit)        return "";    while (value[begin++] <= '\u0020');    int end = limit;    while (value[--end] <= '\u0020');    return substring(begin - offset - 1, end - offset + 1);  }  /**   * Returns this, as it is already a String!   *   * @return this   */  public String toString()  {    return this;  }  /**   * Copies the contents of this String into a character array. Subsequent   * changes to the array do not affect the String.   *   * @return character array copying the String   */  public char[] toCharArray()  {    if (count == value.length)      return (char[]) value.clone();    char[] copy = new char[count];    VMSystem.arraycopy(value, offset, copy, 0, count);    return copy;  }  /**   * Returns a String representation of an Object. This is "null" if the   * object is null, otherwise it is <code>obj.toString()</code> (which   * can be null).   *   * @param obj the Object   * @return the string conversion of obj   */  public static String valueOf(Object obj)  {    return obj == null ? "null" : obj.toString();  }  /**   * Returns a String representation of a character array. Subsequent   * changes to the array do not affect the String.   *   * @param data the character array   * @return a String containing the same character sequence as data   * @throws NullPointerException if data is null   * @see #valueOf(char[], int, int)   * @see #String(char[])   */  public static String valueOf(char[] data)  {    return valueOf (data, 0, data.length);  }  /**   * Returns a String representing the character sequence of the char array,   * starting at the specified offset, and copying chars up to the specified   * count. Subsequent changes to the array do not affect the String.   *   * @param data character array   * @param offset position (base 0) to start copying out of data   * @param count the number of characters from data to copy   * @return String containing the chars from data[offset..offset+count]   * @throws NullPointerException if data is null   * @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0   *         || offset + count &lt; 0 (overflow)   *         || offset + count &gt; data.length)   *         (while unspecified, this is a StringIndexOutOfBoundsException)   * @see #String(char[], int, int)   */  public static String valueOf(char[] data, int offset, int count)  {    return new String(data, offset, count, false);  }  /**   * Returns a String representing the character sequence of the char array,   * starting at the specified offset, and copying chars up to the specified   * count. Subsequent changes to the array do not affect the String.   *   * @param data character array   * @param offset position (base 0) to start copying out of data   * @param count the number of characters from data to copy   * @return String containing the chars from data[offset..offset+count]   * @throws NullPointerException if data is null   * @throws IndexOutOfBoundsException if (offset &lt; 0 || count &lt; 0   *         || offset + count &lt; 0 (overflow)   *         || offset + count &gt; data.length)   *         (while unspecified, this is a StringIndexOutOfBoundsException)   * @see #String(char[], int, int)   */  public static String copyValueOf(char[] data, int offset, int count)  {    return new String(data, offset, count, false);  }  /**   * Returns a String representation of a character array. Subsequent   * changes to the array do not affect the String.   *   * @param data the character array   * @return a String containing the same character sequence as data   * @throws NullPointerException if data is null   * @see #copyValueOf(char[], int, int)   * @see #String(char[])   */  public static String copyValueOf(char[] data)  {    return copyValueOf (data, 0, data.length);  }  /**   * Returns a String representing a boolean.   *   * @param b the boolean   * @return "true" if b is true, else "false"   */  public static String valueOf(boolean b)  {    return b ? "true" : "false";  }  /**   * Returns a String representing a character.   *   * @param c the character   * @return String containing the single character c   */  public static String valueOf(char c)  {    // Package constructor avoids an array copy.    return new String(new char[] { c }, 0, 1, true);  }  /**   * Returns a String representing an integer.   *   * @param i the integer   * @return String containing the integer in base 10   * @see Integer#toString(int)   */  public static String valueOf(int i)  {    // See Integer to understand why we call the two-arg variant.    return Integer.toString(i, 10);  }  /**   * Returns a String representing a long.   *   * @param l the long   * @return String containing the long in base 10   * @see Long#toString(long)   */  public static String valueOf(long l)  {    return Long.toString(l);  }  /**   * Returns a String representing a float.   *   * @param f the float   * @return String containing the float   * @see Float#toString(float)   */  public static String valueOf(float f)  {    return Float.toString(f);  }  /**   * Returns a String representing a double.   *   * @param d the double   * @return String containing the double   * @see Double#toString(double)   */  public static String valueOf(double d)  {    return Double.toString(d);  }  /**   * If two Strings are considered equal, by the equals() method,    * then intern() will return the same String instance. ie.    * if (s1.equals(s2)) then (s1.intern() == s2.intern()).    * All string literals and string-valued constant expressions    * are already interned.   *   * @return the interned String   */  public String intern()  {    return VMString.intern(this);  }  /**   * Return the number of code points between two indices in the   * <code>StringBuffer</code>.  An unpaired surrogate counts as a   * code point for this purpose.  Characters outside the indicated   * range are not examined, even if the range ends in the middle of a   * surrogate pair.   *   * @param start the starting index   * @param end one past the ending index   * @return the number of code points   * @since 1.5   */  public synchronized int codePointCount(int start, int end)  {    if (start < 0 || end >= count || start > end)      throw new StringIndexOutOfBoundsException();    start += offset;    end += offset;    int count = 0;    while (start < end)      {	char base = value[start];	if (base < Character.MIN_HIGH_SURROGATE	    || base > Character.MAX_HIGH_SURROGATE	    || start == end	    || start == count	    || value[start + 1] < Character.MIN_LOW_SURROGATE	    || value[start + 1] > Character.MAX_LOW_SURROGATE)	  {	    // Nothing.	  }	else	  {	    // Surrogate pair.	    ++start;	  }	++start;	++count;      }    return count;  }  /**   * Helper function used to detect which characters have a multi-character   * uppercase expansion. Note that this is only used in locations which   * track one-to-many capitalization (java.lang.Character does not do this).   * As of Unicode 3.0.0, the result is limited in the range 0 to 2, as the   * longest uppercase expansion is three characters (a growth of 2 from the   * lowercase character).   *   * @param ch the char to check   * @return the number of characters to add when converting to uppercase   * @see CharData#DIRECTION   * @see CharData#UPPER_SPECIAL   * @see #toUpperCase(Locale)   */  private static int upperCaseExpansion(char ch)  {    return Character.direction[Character.readChar(ch) >> 7] & 3;  }  /**   * Helper function used to locate the offset in upperExpand given a   * character with a multi-character expansion. The binary search is   * optimized under the assumption that this method will only be called on   * characters which exist in upperSpecial.   *   * @param ch the char to check   * @return the index where its expansion begins   * @see CharData#UPPER_SPECIAL   * @see CharData#UPPER_EXPAND   * @see #toUpperCase(Locale)   */  private static int upperCaseIndex(char ch)  {    // Simple binary search for the correct character.    int low = 0;    int hi = upperSpecial.length - 2;    int mid = ((low + hi) >> 2) << 1;    char c = upperSpecial[mid];    while (ch != c)      {        if (ch < c)          hi = mid - 2;        else          low = mid + 2;        mid = ((low + hi) >> 2) << 1;        c = upperSpecial[mid];      }    return upperSpecial[mid + 1];  }  /**   * Returns the value array of the given string if it is zero based or a   * copy of it that is zero based (stripping offset and making length equal   * to count). Used for accessing the char[]s of gnu.java.lang.CharData.   * Package private for use in Character.   */  static char[] zeroBasedStringValue(String s)  {    char[] value;    if (s.offset == 0 && s.count == s.value.length)      value = s.value;    else      {	int count = s.count;	value = new char[count];	VMSystem.arraycopy(s.value, s.offset, value, 0, count);      }    return value;  }    /**   * Returns true iff this String contains the sequence of Characters   * described in s.   * @param s the CharSequence   * @return true iff this String contains s   */  public boolean contains (CharSequence s)  {    return this.indexOf(s.toString()) != -1;  }    /**   * Returns a string that is this string with all instances of the sequence   * represented by <code>target</code> replaced by the sequence in    * <code>replacement</code>.   * @param target the sequence to be replaced   * @param replacement the sequence used as the replacement   * @return the string constructed as above   */  public String replace (CharSequence target, CharSequence replacement)  {    String targetString = target.toString();    String replaceString = replacement.toString();    int targetLength = target.length();    int replaceLength = replacement.length();        int startPos = this.indexOf(targetString);    StringBuilder result = new StringBuilder(this);        while (startPos != -1)      {        // Replace the target with the replacement        result.replace(startPos, startPos + targetLength, replaceString);        // Search for a new occurrence of the target        startPos = result.indexOf(targetString, startPos + replaceLength);      }    return result.toString();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -