java.lang.String (JDK 1.0)
The String class represents a string of characters. A String object is created by the Java compiler whenever it encounters a string in doublequotes--this method of creation is usually simpler than using a constructor. A number of the methods of this class provide useful string manipulation functions. length() returns the number of characters in a string. charAt() extracts a character from a string. compareTo() compares two strings. equalsIgnoreCase() tests string for equality, ignoring case. startsWith() and endsWith() compare the start and end of a string to a specified value. indexOf() and lastIndexOf() search forward and backwards in a string for a specified character or substring. substring() returns a substring of a string. replace() creates a new copy of the string with one character replaced by another. toUpperCase() and toLowerCase() convert the case of a string. trim() strips whitespace from the start and end of a string. concat() concatenates two strings, which can also be done with the + operator.
Note that String objects are immutable--there is no setCharAt() method to change the contents. The methods above that return a String do not modify the string they are passed, but instead return a modified copy of the string. Use a StringBuffer if you want to manipulate the contents of a string, or use toCharArray() to convert a string to an array of char values.
The static valueOf() methods convert various Java primitive types to strings.
public final classStringextends Object implements Serializable { //Public ConstructorspublicString(); publicString(Stringvalue); publicString(char[]value); publicString(char[]value, intoffset, intcount); # publicString(byte[]ascii, inthibyte, intoffset, intcount); # publicString(byte[]ascii, inthibyte); 1.1publicString(byte[]bytes, intoffset, intlength, Stringenc) throws UnsupportedEncodingException; 1.1publicString(byte[]bytes, Stringenc) throws UnsupportedEncodingException; 1.1publicString(byte[]bytes, intoffset, intlength); 1.1publicString(byte[]bytes); publicString(StringBufferbuffer); //Class Methodspublic static StringcopyValueOf(char[]data, intoffset, intcount); public static StringcopyValueOf(char[]data); public static StringvalueOf(Objectobj); public static StringvalueOf(char[]data); public static StringvalueOf(char[]data, intoffset, intcount); public static StringvalueOf(booleanb); public static StringvalueOf(charc); public static StringvalueOf(inti); public static StringvalueOf(longl); public static StringvalueOf(floatf); public static StringvalueOf(doubled); //Public Instance Methodspublic charcharAt(intindex); public intcompareTo(StringanotherString); public Stringconcat(Stringstr); public booleanendsWith(Stringsuffix); public booleanequals(ObjectanObject); //Overrides Objectpublic booleanequalsIgnoreCase(StringanotherString); # public voidgetBytes(intsrcBegin, intsrcEnd, byte[]dst, intdstBegin); 1.1public byte[]getBytes(Stringenc) throws UnsupportedEncodingException; 1.1public byte[]getBytes(); public voidgetChars(intsrcBegin, intsrcEnd, char[]dst, intdstBegin); public inthashCode(); //Overrides Objectpublic intindexOf(intch); public intindexOf(intch, intfromIndex); public intindexOf(Stringstr); public intindexOf(Stringstr, intfromIndex); public native Stringintern(); public intlastIndexOf(intch); public intlastIndexOf(intch, intfromIndex); public intlastIndexOf(Stringstr); public intlastIndexOf(Stringstr, intfromIndex); public intlength(); public booleanregionMatches(inttoffset, Stringother, intooffset, intlen); public booleanregionMatches(booleanignoreCase, inttoffset, Stringother, intooffset, intlen); public Stringreplace(charoldChar, charnewChar); public booleanstartsWith(Stringprefix, inttoffset); public booleanstartsWith(Stringprefix); public Stringsubstring(intbeginIndex); public Stringsubstring(intbeginIndex, intendIndex); public char[]toCharArray(); 1.1public StringtoLowerCase(Localelocale); public StringtoLowerCase(); public StringtoString(); //Overrides Object1.1public StringtoUpperCase(Localelocale); public StringtoUpperCase(); public Stringtrim(); }
Passed To:
Many methods
Returned By:
Many methods
Type Of:
BorderLayout.CENTER, BorderLayout.EAST, BorderLayout.NORTH, BorderLayout.SOUTH, BorderLayout.WEST, File.pathSeparator, File.separator, Font.name, HttpURLConnection.method, HttpURLConnection.responseMessage, InvalidClassException.classname, StreamTokenizer.sval, StringBufferInputStream.buffer