< prev index next >

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

Print this page




  57  * @spec JSR-51
  58  */
  59 
  60 public interface CharSequence {
  61 
  62     /**
  63      * Returns the length of this character sequence.  The length is the number
  64      * of 16-bit {@code char}s in the sequence.
  65      *
  66      * @return  the number of {@code char}s in this sequence
  67      */
  68     int length();
  69 
  70     /**
  71      * Returns the {@code char} value at the specified index.  An index ranges from zero
  72      * to {@code length() - 1}.  The first {@code char} value of the sequence is at
  73      * index zero, the next at index one, and so on, as for array
  74      * indexing.
  75      *
  76      * <p>If the {@code char} value specified by the index is a
  77      * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
  78      * value is returned.
  79      *
  80      * @param   index   the index of the {@code char} value to be returned
  81      *
  82      * @return  the specified {@code char} value
  83      *
  84      * @throws  IndexOutOfBoundsException
  85      *          if the {@code index} argument is negative or not less than
  86      *          {@code length()}
  87      */
  88     char charAt(int index);
  89 
  90     /**
  91      * Returns a {@code CharSequence} that is a subsequence of this sequence.
  92      * The subsequence starts with the {@code char} value at the specified index and
  93      * ends with the {@code char} value at index {@code end - 1}.  The length
  94      * (in {@code char}s) of the
  95      * returned sequence is {@code end - start}, so if {@code start == end}
  96      * then an empty sequence is returned.
  97      *


 102      *
 103      * @throws  IndexOutOfBoundsException
 104      *          if {@code start} or {@code end} are negative,
 105      *          if {@code end} is greater than {@code length()},
 106      *          or if {@code start} is greater than {@code end}
 107      */
 108     CharSequence subSequence(int start, int end);
 109 
 110     /**
 111      * Returns a string containing the characters in this sequence in the same
 112      * order as this sequence.  The length of the string will be the length of
 113      * this sequence.
 114      *
 115      * @return  a string consisting of exactly this sequence of characters
 116      */
 117     public String toString();
 118 
 119     /**
 120      * Returns a stream of {@code int} zero-extending the {@code char} values
 121      * from this sequence.  Any char which maps to a <a
 122      * href="{@docRoot}/java/lang/Character.html#unicode">surrogate code
 123      * point</a> is passed through uninterpreted.
 124      *
 125      * <p>The stream binds to this sequence when the terminal stream operation
 126      * commences (specifically, for mutable sequences the spliterator for the
 127      * stream is <a href="../util/Spliterator.html#binding"><em>late-binding</em></a>).
 128      * If the sequence is modified during that operation then the result is
 129      * undefined.
 130      *
 131      * @return an IntStream of char values from this sequence
 132      * @since 1.8
 133      */
 134     public default IntStream chars() {
 135         class CharIterator implements PrimitiveIterator.OfInt {
 136             int cur = 0;
 137 
 138             public boolean hasNext() {
 139                 return cur < length();
 140             }
 141 
 142             public int nextInt() {




  57  * @spec JSR-51
  58  */
  59 
  60 public interface CharSequence {
  61 
  62     /**
  63      * Returns the length of this character sequence.  The length is the number
  64      * of 16-bit {@code char}s in the sequence.
  65      *
  66      * @return  the number of {@code char}s in this sequence
  67      */
  68     int length();
  69 
  70     /**
  71      * Returns the {@code char} value at the specified index.  An index ranges from zero
  72      * to {@code length() - 1}.  The first {@code char} value of the sequence is at
  73      * index zero, the next at index one, and so on, as for array
  74      * indexing.
  75      *
  76      * <p>If the {@code char} value specified by the index is a
  77      * <a href="{@docRoot}/java.base/java/lang/Character.html#unicode">surrogate</a>, the surrogate
  78      * value is returned.
  79      *
  80      * @param   index   the index of the {@code char} value to be returned
  81      *
  82      * @return  the specified {@code char} value
  83      *
  84      * @throws  IndexOutOfBoundsException
  85      *          if the {@code index} argument is negative or not less than
  86      *          {@code length()}
  87      */
  88     char charAt(int index);
  89 
  90     /**
  91      * Returns a {@code CharSequence} that is a subsequence of this sequence.
  92      * The subsequence starts with the {@code char} value at the specified index and
  93      * ends with the {@code char} value at index {@code end - 1}.  The length
  94      * (in {@code char}s) of the
  95      * returned sequence is {@code end - start}, so if {@code start == end}
  96      * then an empty sequence is returned.
  97      *


 102      *
 103      * @throws  IndexOutOfBoundsException
 104      *          if {@code start} or {@code end} are negative,
 105      *          if {@code end} is greater than {@code length()},
 106      *          or if {@code start} is greater than {@code end}
 107      */
 108     CharSequence subSequence(int start, int end);
 109 
 110     /**
 111      * Returns a string containing the characters in this sequence in the same
 112      * order as this sequence.  The length of the string will be the length of
 113      * this sequence.
 114      *
 115      * @return  a string consisting of exactly this sequence of characters
 116      */
 117     public String toString();
 118 
 119     /**
 120      * Returns a stream of {@code int} zero-extending the {@code char} values
 121      * from this sequence.  Any char which maps to a <a
 122      * href="{@docRoot}/java.base/java/lang/Character.html#unicode">surrogate code
 123      * point</a> is passed through uninterpreted.
 124      *
 125      * <p>The stream binds to this sequence when the terminal stream operation
 126      * commences (specifically, for mutable sequences the spliterator for the
 127      * stream is <a href="../util/Spliterator.html#binding"><em>late-binding</em></a>).
 128      * If the sequence is modified during that operation then the result is
 129      * undefined.
 130      *
 131      * @return an IntStream of char values from this sequence
 132      * @since 1.8
 133      */
 134     public default IntStream chars() {
 135         class CharIterator implements PrimitiveIterator.OfInt {
 136             int cur = 0;
 137 
 138             public boolean hasNext() {
 139                 return cur < length();
 140             }
 141 
 142             public int nextInt() {


< prev index next >