1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package java.lang; 19 20 21 /** 22 * This interface represents an ordered set of characters and defines the 23 * methods to probe them. 24 */ 25 public interface CharSequence { 26 27 /** 28 * Returns the number of characters in this sequence. 29 * 30 * @return the number of characters. 31 */ length()32 public int length(); 33 34 /** 35 * Returns the character at the specified index, with the first character 36 * having index zero. 37 * 38 * @param index 39 * the index of the character to return. 40 * @return the requested character. 41 * @throws IndexOutOfBoundsException 42 * if {@code index < 0} or {@code index} is greater than the 43 * length of this sequence. 44 */ charAt(int index)45 public char charAt(int index); 46 47 /** 48 * Returns a {@code CharSequence} from the {@code start} index (inclusive) 49 * to the {@code end} index (exclusive) of this sequence. 50 * 51 * @param start 52 * the start offset of the sub-sequence. It is inclusive, that 53 * is, the index of the first character that is included in the 54 * sub-sequence. 55 * @param end 56 * the end offset of the sub-sequence. It is exclusive, that is, 57 * the index of the first character after those that are included 58 * in the sub-sequence 59 * @return the requested sub-sequence. 60 * @throws IndexOutOfBoundsException 61 * if {@code start < 0}, {@code end < 0}, {@code start > end}, 62 * or if {@code start} or {@code end} are greater than the 63 * length of this sequence. 64 */ subSequence(int start, int end)65 public CharSequence subSequence(int start, int end); 66 67 /** 68 * Returns a string with the same characters in the same order as in this 69 * sequence. 70 * 71 * @return a string based on this sequence. 72 */ toString()73 public String toString(); 74 } 75