< prev index next >

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

Print this page




2630      *          trailing white space.
2631      */
2632     public String trim() {
2633         String ret = isLatin1() ? StringLatin1.trim(value)
2634                                 : StringUTF16.trim(value);
2635         return ret == null ? this : ret;
2636     }
2637 
2638     /**
2639      * This object (which is already a string!) is itself returned.
2640      *
2641      * @return  the string itself.
2642      */
2643     public String toString() {
2644         return this;
2645     }
2646 
2647     /**
2648      * Returns a stream of {@code int} zero-extending the {@code char} values
2649      * from this sequence.  Any char which maps to a <a
2650      * href="{@docRoot}/java/lang/Character.html#unicode">surrogate code
2651      * point</a> is passed through uninterpreted.
2652      *
2653      * @return an IntStream of char values from this sequence
2654      * @since 9
2655      */
2656     @Override
2657     public IntStream chars() {
2658         return StreamSupport.intStream(
2659             isLatin1() ? new StringLatin1.CharsSpliterator(value, Spliterator.IMMUTABLE)
2660                        : new StringUTF16.CharsSpliterator(value, Spliterator.IMMUTABLE),
2661             false);
2662     }
2663 
2664 
2665     /**
2666      * Returns a stream of code point values from this sequence.  Any surrogate
2667      * pairs encountered in the sequence are combined as if by {@linkplain
2668      * Character#toCodePoint Character.toCodePoint} and the result is passed
2669      * to the stream. Any other code units, including ordinary BMP characters,
2670      * unpaired surrogates, and undefined code units, are zero-extended to




2630      *          trailing white space.
2631      */
2632     public String trim() {
2633         String ret = isLatin1() ? StringLatin1.trim(value)
2634                                 : StringUTF16.trim(value);
2635         return ret == null ? this : ret;
2636     }
2637 
2638     /**
2639      * This object (which is already a string!) is itself returned.
2640      *
2641      * @return  the string itself.
2642      */
2643     public String toString() {
2644         return this;
2645     }
2646 
2647     /**
2648      * Returns a stream of {@code int} zero-extending the {@code char} values
2649      * from this sequence.  Any char which maps to a <a
2650      * href="{@docRoot}/java.base/java/lang/Character.html#unicode">surrogate code
2651      * point</a> is passed through uninterpreted.
2652      *
2653      * @return an IntStream of char values from this sequence
2654      * @since 9
2655      */
2656     @Override
2657     public IntStream chars() {
2658         return StreamSupport.intStream(
2659             isLatin1() ? new StringLatin1.CharsSpliterator(value, Spliterator.IMMUTABLE)
2660                        : new StringUTF16.CharsSpliterator(value, Spliterator.IMMUTABLE),
2661             false);
2662     }
2663 
2664 
2665     /**
2666      * Returns a stream of code point values from this sequence.  Any surrogate
2667      * pairs encountered in the sequence are combined as if by {@linkplain
2668      * Character#toCodePoint Character.toCodePoint} and the result is passed
2669      * to the stream. Any other code units, including ordinary BMP characters,
2670      * unpaired surrogates, and undefined code units, are zero-extended to


< prev index next >