string.java
来自「Mac OS X 10.4.9 for x86 Source Code gcc」· Java 代码 · 共 1,258 行 · 第 1/3 页
JAVA
1,258 行
* @return new String which is a substring of this String * @throws IndexOutOfBoundsException if begin < 0 || end > length() * || begin > end (while unspecified, this is a * StringIndexOutOfBoundsException) */ public native String substring(int begin, int end); /** * Creates a substring of this String, starting at a specified index * and ending at one character before a specified index. This behaves like * <code>substring(begin, end)</code>. * * @param begin index to start substring (inclusive, base 0) * @param end index to end at (exclusive) * @return new String which is a substring of this String * @throws IndexOutOfBoundsException if begin < 0 || end > length() * || begin > end * @since 1.4 */ public CharSequence subSequence(int begin, int end) { return substring(begin, end); } /** * Concatenates a String to this String. This results in a new string unless * one of the two originals is "". * * @param str String to append to this String * @return newly concatenated String * @throws NullPointerException if str is null */ public native String concat(String str); /** * Replaces every instance of a character in this String with a new * character. If no replacements occur, this is returned. * * @param oldChar the old character to replace * @param newChar the new character * @return new String with all instances of oldChar replaced with newChar */ public native String replace(char oldChar, char newChar); /** * Test if this String matches a regular expression. This is shorthand for * <code>{@link Pattern}.matches(regex, this)</code>. * * @param regex the pattern to match * @return true if the pattern matches * @throws NullPointerException if regex is null * @throws PatternSyntaxException if regex is invalid * @see Pattern#matches(String, CharSequence) * @since 1.4 */ public boolean matches(String regex) { return Pattern.matches(regex, this); } /** * Replaces the first substring match of the regular expression with a * given replacement. This is shorthand for <code>{@link Pattern} * .compile(regex).matcher(this).replaceFirst(replacement)</code>. * * @param regex the pattern to match * @param replacement the replacement string * @return the modified string * @throws NullPointerException if regex or replacement is null * @throws PatternSyntaxException if regex is invalid * @see #replaceAll(String, String) * @see Pattern#compile(String) * @see Pattern#matcher(CharSequence) * @see Matcher#replaceFirst(String) * @since 1.4 */ public String replaceFirst(String regex, String replacement) { return Pattern.compile(regex).matcher(this).replaceFirst(replacement); } /** * Replaces all matching substrings of the regular expression with a * given replacement. This is shorthand for <code>{@link Pattern} * .compile(regex).matcher(this).replaceAll(replacement)</code>. * * @param regex the pattern to match * @param replacement the replacement string * @return the modified string * @throws NullPointerException if regex or replacement is null * @throws PatternSyntaxException if regex is invalid * @see #replaceFirst(String, String) * @see Pattern#compile(String) * @see Pattern#matcher(CharSequence) * @see Matcher#replaceAll(String) * @since 1.4 */ public String replaceAll(String regex, String replacement) { return Pattern.compile(regex).matcher(this).replaceAll(replacement); } /** * Split this string around the matches of a regular expression. Each * element of the returned array is the largest block of characters not * terminated by the regular expression, in the order the matches are found. * * <p>The limit affects the length of the array. If it is positive, the * array will contain at most n elements (n - 1 pattern matches). If * negative, the array length is unlimited, but there can be trailing empty * entries. if 0, the array length is unlimited, and trailing empty entries * are discarded. * * <p>For example, splitting "boo:and:foo" yields:<br> * <table border=0> * <th><td>Regex</td> <td>Limit</td> <td>Result</td></th> * <tr><td>":"</td> <td>2</td> <td>{ "boo", "and:foo" }</td></tr> * <tr><td>":"</td> <td>t</td> <td>{ "boo", "and", "foo" }</td></tr> * <tr><td>":"</td> <td>-2</td> <td>{ "boo", "and", "foo" }</td></tr> * <tr><td>"o"</td> <td>5</td> <td>{ "b", "", ":and:f", "", "" }</td></tr> * <tr><td>"o"</td> <td>-2</td> <td>{ "b", "", ":and:f", "", "" }</td></tr> * <tr><td>"o"</td> <td>0</td> <td>{ "b", "", ":and:f" }</td></tr> * </table> * * <p>This is shorthand for * <code>{@link Pattern}.compile(regex).split(this, limit)</code>. * * @param regex the pattern to match * @param limit the limit threshold * @return the array of split strings * @throws NullPointerException if regex or replacement is null * @throws PatternSyntaxException if regex is invalid * @see Pattern#compile(String) * @see Pattern#split(CharSequence, int) * @since 1.4 */ public String[] split(String regex, int limit) { return Pattern.compile(regex).split(this, limit); } /** * Split this string around the matches of a regular expression. Each * element of the returned array is the largest block of characters not * terminated by the regular expression, in the order the matches are found. * The array length is unlimited, and trailing empty entries are discarded, * as though calling <code>split(regex, 0)</code>. * * @param regex the pattern to match * @return the array of split strings * @throws NullPointerException if regex or replacement is null * @throws PatternSyntaxException if regex is invalid * @see #split(String, int) * @see Pattern#compile(String) * @see Pattern#split(CharSequence, int) * @since 1.4 */ public String[] split(String regex) { return Pattern.compile(regex).split(this, 0); } /** * Lowercases this String according to a particular locale. This uses * Unicode's special case mappings, as applied to the given Locale, so the * resulting string may be a different length. * * @param loc locale to use * @return new lowercased String, or this if no characters were lowercased * @throws NullPointerException if loc is null * @see #toUpperCase(Locale) * @since 1.1 */ public native String toLowerCase(Locale locale); /** * Lowercases this String. This uses Unicode's special case mappings, as * applied to the platform's default Locale, so the resulting string may * be a different length. * * @return new lowercased String, or this if no characters were lowercased * @see #toLowerCase(Locale) * @see #toUpperCase() */ public String toLowerCase() { // The JDK is a bit confused about what to do here. If we pass in // the default Locale then special Locale handling might be // invoked. However, the docs also say that Character.toLowerCase // rules here. We go with the latter. return toLowerCase (null); } /** * Uppercases this String according to a particular locale. This uses * Unicode's special case mappings, as applied to the given Locale, so the * resulting string may be a different length. * * @param loc locale to use * @return new uppercased String, or this if no characters were uppercased * @throws NullPointerException if loc is null * @see #toLowerCase(Locale) * @since 1.1 */ public native String toUpperCase(Locale locale); /** * Uppercases this String. This uses Unicode's special case mappings, as * applied to the platform's default Locale, so the resulting string may * be a different length. * * @return new uppercased String, or this if no characters were uppercased * @see #toUpperCase(Locale) * @see #toLowerCase() */ public String toUpperCase() { // The JDK is a bit confused about what to do here. If we pass in // the default Locale then special Locale handling might be // invoked. However, the docs also say that Character.toLowerCase // rules here. We go with the latter. return toUpperCase (null); } /** * 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#whitespace(char)}. * * @return new trimmed String, or this if nothing trimmed */ public native String trim(); /** * 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 native char[] toCharArray(); /** * 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 < 0 || count < 0 * || offset + count > data.length) * (while unspecified, this is a StringIndexOutOfBoundsException) * @see #String(char[], int, int) */ public static native String valueOf(char[] data, int offset, int count); /** * 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 < 0 || count < 0 * || offset + count > data.length) * (while unspecified, this is a StringIndexOutOfBoundsException) * @see #String(char[], int, int) */ public static String copyValueOf(char[] data, int offset, int count) { String r = new String (); r.init(data, offset, count, false); return r; } /** * 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 native String valueOf(char c); /** * Returns a String representing an integer. * * @param i the integer * @return String containing the integer in base 10 * @see Integer#toString(int) */ public static native String valueOf(int i); /** * 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); } /** * Fetches this String from the intern hashtable. 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 native String intern(); private native void init(char[] chars, int offset, int count, boolean dont_copy); private native void init(byte[] chars, int hibyte, int offset, int count); private native void init(byte[] chars, int offset, int count, String enc) throws UnsupportedEncodingException; private native void init(gnu.gcj.runtime.StringBuffer buffer);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?