1. /*
  2. * @(#)CharSequence.java 1.6 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang;
  8. /**
  9. * A <tt>CharSequence</tt> is a readable sequence of characters. This
  10. * interface provides uniform, read-only access to many different kinds of
  11. * character sequences.
  12. *
  13. * <p> This interface does not refine the general contracts of the {@link
  14. * java.lang.Object#equals(java.lang.Object) equals} and {@link
  15. * java.lang.Object#hashCode() hashCode} methods. The result of comparing two
  16. * objects that implement <tt>CharSequence</tt> is therefore, in general,
  17. * undefined. Each object may be implemented by a different class, and there
  18. * is no guarantee that each class will be capable of testing its instances
  19. * for equality with those of the other. It is therefore inappropriate to use
  20. * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
  21. * a map. </p>
  22. *
  23. * @author Mike McCloskey
  24. * @version 1.6 03/01/23
  25. * @since 1.4
  26. * @spec JSR-51
  27. */
  28. public interface CharSequence {
  29. /**
  30. * Returns the length of this character sequence. The length is the number
  31. * of 16-bit Unicode characters in the sequence. </p>
  32. *
  33. * @return the number of characters in this sequence
  34. */
  35. int length();
  36. /**
  37. * Returns the character at the specified index. An index ranges from zero
  38. * to <tt>length() - 1</tt>. The first character of the sequence is at
  39. * index zero, the next at index one, and so on, as for array
  40. * indexing. </p>
  41. *
  42. * @param index the index of the character to be returned
  43. *
  44. * @return the specified character
  45. *
  46. * @throws IndexOutOfBoundsException
  47. * if the <tt>index</tt> argument is negative or not less than
  48. * <tt>length()</tt>
  49. */
  50. char charAt(int index);
  51. /**
  52. * Returns a new character sequence that is a subsequence of this sequence.
  53. * The subsequence starts with the character at the specified index and
  54. * ends with the character at index <tt>end - 1</tt>. The length of the
  55. * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
  56. * then an empty sequence is returned. </p>
  57. *
  58. * @param start the start index, inclusive
  59. * @param end the end index, exclusive
  60. *
  61. * @return the specified subsequence
  62. *
  63. * @throws IndexOutOfBoundsException
  64. * if <tt>start</tt> or <tt>end</tt> are negative,
  65. * if <tt>end</tt> is greater than <tt>length()</tt>,
  66. * or if <tt>start</tt> is greater than <tt>end</tt>
  67. */
  68. CharSequence subSequence(int start, int end);
  69. /**
  70. * Returns a string containing the characters in this sequence in the same
  71. * order as this sequence. The length of the string will be the length of
  72. * this sequence. </p>
  73. *
  74. * @return a string consisting of exactly this sequence of characters
  75. */
  76. public String toString();
  77. }