Les chaines de caracteres |
Java fait une distinction nette entre les chaines de caracteres constantes et celles qui peuvent varier. La premiere categorie est definie dans la classe java.lang.String alors que la seconde l'est dans java.lang.StringBuffer.
public final class String
{ String() Allocates a new String containing no characters. String(byte[]) Construct a new String by converting the specified array of bytes using the platform's default character encoding. String(byte[], int) Allocates a new String containing characters constructed from an array of 8-bit integer values. Deprecated. String(byte[], int, int) Construct a new String by converting the specified subarray of bytes using the platform's default character encoding. String(byte[], int, int, int) Allocates a new String constructed from a subarray of an array of 8-bit integer values. Deprecated. String(byte[], int, int, String) Construct a new String by converting the specified subarray of bytes using the specified character encoding. String(byte[], String) Construct a new String by converting the specified array of bytes using the specified character encoding. String(char[]) Allocates a new String so that it represents the sequence of characters currently contained in the character array argument. String(char[], int, int) Allocates a new String that contains characters from a subarray of the character array argument. String(String) Allocates a new string that contains the same sequence of characters as the string argument. String(StringBuffer) Allocates a new string that contains the sequence of characters currently contained in the string buffer argument. charAt(int) Returns the character at the specified index. compareTo(String) Compares two strings lexicographically. concat(String) Concatenates the specified string to the end of this string. copyValueOf(char[]) Returns a String that is equivalent to the specified character array. copyValueOf(char[], int, int) Returns a String that is equivalent to the specified character array. endsWith(String) Tests if this string ends with the specified suffix. equals(Object) Compares this string to the specified object. equalsIgnoreCase(String) Compares this String to another object. getBytes() Convert this String into bytes according to the platform's default character encoding, storing the result into a new byte array. getBytes(int, int, byte[], int) Copies characters from this string into the destination byte array. Deprecated. getBytes(String) Convert this String into bytes according to the specified character encoding, storing the result into a new byte array. getChars(int, int, char[], int) Copies characters from this string into the destination character array. hashCode() Returns a hashcode for this string. indexOf(int) Returns the index within this string of the first occurrence of the specified character. indexOf(int, int) Returns the index within this string of the first occurrence of the specified character, starting the search at the specified index. indexOf(String) Returns the index within this string of the first occurrence of the specified substring. indexOf(String, int) Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. intern() Returns a canonical representation for the string object. lastIndexOf(int) Returns the index within this string of the last occurrence of the specified character. lastIndexOf(int, int) Returns the index within this string of the last occurrence of the specified character, searching backward starting at the specified index. lastIndexOf(String) Returns the index within this string of the rightmost occurrence of the specified substring. lastIndexOf(String, int) Returns the index within this string of the last occurrence of the specified substring. length() Returns the length of this string. regionMatches(boolean, int, String, int, int) Tests if two string regions are equal. regionMatches(int, String, int, int) Tests if two string regions are equal. replace(char, char) Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar. startsWith(String) Tests if this string starts with the specified prefix. startsWith(String, int) Tests if this string starts with the specified prefix. substring(int) Returns a new string that is a substring of this string. substring(int, int) Returns a new string that is a substring of this string. toCharArray() Converts this string to a new character array. toLowerCase() Converts this string to lowercase. toLowerCase(Locale) Converts all of the characters in this String to lower case using the rules of the given locale. toString() This object (which is already a string!) is itself returned. toUpperCase() Converts this string to uppercase. toUpperCase(Locale) Converts all of the characters in this String to upper case using the rules of the given locale. trim() Removes white space from both ends of this string. valueOf(boolean) Returns the string representation of the boolean argument. valueOf(char) Returns the string representation of the char * argument. valueOf(char[]) Returns the string representation of the char array argument. valueOf(char[], int, int) Returns the string representation of a specific subarray of the char array argument. valueOf(double) Returns the string representation of the double argument. valueOf(float) Returns the string representation of the float argument. valueOf(int) Returns the string representation of the int argument. valueOf(long) Returns the string representation of the long argument. valueOf(Object) Returns the string representation of the Object argument. } public final StringBuffer { StringBuffer() Constructs a string buffer with no characters in it and an initial capacity of 16 characters. StringBuffer(int) Constructs a string buffer with no characters in it and an initial capacity specified by the length argument. StringBuffer(String) Constructs a string buffer so that it represents the same sequence of characters as the string argument. append(boolean) Appends the string representation of the boolean argument to the string buffer. append(char) Appends the string representation of the char argument to this string buffer. append(char[]) Appends the string representation of the char array argument to this string buffer. append(char[], int, int) Appends the string representation of a subarray of the char array argument to this string buffer. append(double) Appends the string representation of the double argument to this string buffer. append(float) Appends the string representation of the float argument to this string buffer. append(int) Appends the string representation of the int argument to this string buffer. append(long) Appends the string representation of the long argument to this string buffer. append(Object) Appends the string representation of the Object argument to this string buffer. append(String) Appends the string to this string buffer. capacity() Returns the current capacity of the String buffer. charAt(int) Returns the character at a specific index in this string buffer. ensureCapacity(int) Ensures that the capacity of the buffer is at least equal to the specified minimum. getChars(int, int, char[], int) Characters are copied from this string buffer into the destination character array dst. insert(int, boolean) Inserts the string representation of the boolean argument into this string buffer. insert(int, char) Inserts the string representation of the char argument into this string buffer. insert(int, char[]) Inserts the string representation of the char array argument into this string buffer. insert(int, double) Inserts the string representation of the double argument into this string buffer. insert(int, float) Inserts the string representation of the float argument into this string buffer. insert(int, int) Inserts the string representation of the second int argument into this string buffer. insert(int, long) Inserts the string representation of the long argument into this string buffer. insert(int, Object) Inserts the string representation of the Object argument into this string buffer. insert(int, String) Inserts the string into this string buffer. length() Returns the length (character count) of this string buffer. reverse() The character sequence contained in this string buffer is replaced by the reverse of the sequence. setCharAt(int, char) The character at the specified index of this string buffer is set to ch. setLength(int) Sets the length of this String buffer. toString() Converts to a string representing the data in this string buffer. } |
NB : Extrait de la doc Sun
Ph. RIS 1997