src/share/classes/java/lang/String.java

Print this page




2633             }
2634         }
2635         return new String(result, 0, resultOffset);
2636     }
2637 
2638     /**
2639      * Converts all of the characters in this {@code String} to lower
2640      * case using the rules of the default locale. This is equivalent to calling
2641      * {@code toLowerCase(Locale.getDefault())}.
2642      * <p>
2643      * <b>Note:</b> This method is locale sensitive, and may produce unexpected
2644      * results if used for strings that are intended to be interpreted locale
2645      * independently.
2646      * Examples are programming language identifiers, protocol keys, and HTML
2647      * tags.
2648      * For instance, {@code "TITLE".toLowerCase()} in a Turkish locale
2649      * returns {@code "t\u005Cu0131tle"}, where '\u005Cu0131' is the
2650      * LATIN SMALL LETTER DOTLESS I character.
2651      * To obtain correct results for locale insensitive strings, use
2652      * {@code toLowerCase(Locale.ROOT)}.
2653      * <p>
2654      * @return  the {@code String}, converted to lowercase.
2655      * @see     java.lang.String#toLowerCase(Locale)
2656      */
2657     public String toLowerCase() {
2658         return toLowerCase(Locale.getDefault());
2659     }
2660 
2661     /**
2662      * Converts all of the characters in this {@code String} to upper
2663      * case using the rules of the given {@code Locale}. Case mapping is based
2664      * on the Unicode Standard version specified by the {@link java.lang.Character Character}
2665      * class. Since case mappings are not always 1:1 char mappings, the resulting
2666      * {@code String} may be a different length than the original {@code String}.
2667      * <p>
2668      * Examples of locale-sensitive and 1:M case mappings are in the following table.
2669      *
2670      * <table border="1" summary="Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description.">
2671      * <tr>
2672      *   <th>Language Code of Locale</th>
2673      *   <th>Lower Case</th>


2795             }
2796         }
2797         return new String(result, 0, resultOffset);
2798     }
2799 
2800     /**
2801      * Converts all of the characters in this {@code String} to upper
2802      * case using the rules of the default locale. This method is equivalent to
2803      * {@code toUpperCase(Locale.getDefault())}.
2804      * <p>
2805      * <b>Note:</b> This method is locale sensitive, and may produce unexpected
2806      * results if used for strings that are intended to be interpreted locale
2807      * independently.
2808      * Examples are programming language identifiers, protocol keys, and HTML
2809      * tags.
2810      * For instance, {@code "title".toUpperCase()} in a Turkish locale
2811      * returns {@code "T\u005Cu0130TLE"}, where '\u005Cu0130' is the
2812      * LATIN CAPITAL LETTER I WITH DOT ABOVE character.
2813      * To obtain correct results for locale insensitive strings, use
2814      * {@code toUpperCase(Locale.ROOT)}.
2815      * <p>
2816      * @return  the {@code String}, converted to uppercase.
2817      * @see     java.lang.String#toUpperCase(Locale)
2818      */
2819     public String toUpperCase() {
2820         return toUpperCase(Locale.getDefault());
2821     }
2822 
2823     /**
2824      * Returns a string whose value is this string, with any leading and trailing
2825      * whitespace removed.
2826      * <p>
2827      * If this {@code String} object represents an empty character
2828      * sequence, or the first and last characters of character sequence
2829      * represented by this {@code String} object both have codes
2830      * greater than {@code '\u005Cu0020'} (the space character), then a
2831      * reference to this {@code String} object is returned.
2832      * <p>
2833      * Otherwise, if there is no character with a code greater than
2834      * {@code '\u005Cu0020'} in the string, then a
2835      * {@code String} object representing an empty string is




2633             }
2634         }
2635         return new String(result, 0, resultOffset);
2636     }
2637 
2638     /**
2639      * Converts all of the characters in this {@code String} to lower
2640      * case using the rules of the default locale. This is equivalent to calling
2641      * {@code toLowerCase(Locale.getDefault())}.
2642      * <p>
2643      * <b>Note:</b> This method is locale sensitive, and may produce unexpected
2644      * results if used for strings that are intended to be interpreted locale
2645      * independently.
2646      * Examples are programming language identifiers, protocol keys, and HTML
2647      * tags.
2648      * For instance, {@code "TITLE".toLowerCase()} in a Turkish locale
2649      * returns {@code "t\u005Cu0131tle"}, where '\u005Cu0131' is the
2650      * LATIN SMALL LETTER DOTLESS I character.
2651      * To obtain correct results for locale insensitive strings, use
2652      * {@code toLowerCase(Locale.ROOT)}.
2653      *
2654      * @return  the {@code String}, converted to lowercase.
2655      * @see     java.lang.String#toLowerCase(Locale)
2656      */
2657     public String toLowerCase() {
2658         return toLowerCase(Locale.getDefault());
2659     }
2660 
2661     /**
2662      * Converts all of the characters in this {@code String} to upper
2663      * case using the rules of the given {@code Locale}. Case mapping is based
2664      * on the Unicode Standard version specified by the {@link java.lang.Character Character}
2665      * class. Since case mappings are not always 1:1 char mappings, the resulting
2666      * {@code String} may be a different length than the original {@code String}.
2667      * <p>
2668      * Examples of locale-sensitive and 1:M case mappings are in the following table.
2669      *
2670      * <table border="1" summary="Examples of locale-sensitive and 1:M case mappings. Shows Language code of locale, lower case, upper case, and description.">
2671      * <tr>
2672      *   <th>Language Code of Locale</th>
2673      *   <th>Lower Case</th>


2795             }
2796         }
2797         return new String(result, 0, resultOffset);
2798     }
2799 
2800     /**
2801      * Converts all of the characters in this {@code String} to upper
2802      * case using the rules of the default locale. This method is equivalent to
2803      * {@code toUpperCase(Locale.getDefault())}.
2804      * <p>
2805      * <b>Note:</b> This method is locale sensitive, and may produce unexpected
2806      * results if used for strings that are intended to be interpreted locale
2807      * independently.
2808      * Examples are programming language identifiers, protocol keys, and HTML
2809      * tags.
2810      * For instance, {@code "title".toUpperCase()} in a Turkish locale
2811      * returns {@code "T\u005Cu0130TLE"}, where '\u005Cu0130' is the
2812      * LATIN CAPITAL LETTER I WITH DOT ABOVE character.
2813      * To obtain correct results for locale insensitive strings, use
2814      * {@code toUpperCase(Locale.ROOT)}.
2815      *
2816      * @return  the {@code String}, converted to uppercase.
2817      * @see     java.lang.String#toUpperCase(Locale)
2818      */
2819     public String toUpperCase() {
2820         return toUpperCase(Locale.getDefault());
2821     }
2822 
2823     /**
2824      * Returns a string whose value is this string, with any leading and trailing
2825      * whitespace removed.
2826      * <p>
2827      * If this {@code String} object represents an empty character
2828      * sequence, or the first and last characters of character sequence
2829      * represented by this {@code String} object both have codes
2830      * greater than {@code '\u005Cu0020'} (the space character), then a
2831      * reference to this {@code String} object is returned.
2832      * <p>
2833      * Otherwise, if there is no character with a code greater than
2834      * {@code '\u005Cu0020'} in the string, then a
2835      * {@code String} object representing an empty string is