P Dunn's Super CS1 Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
P Dunn's Super CS1 Site  
 
 
 
Class Notes

Monday November 6 , 2000
 
String Processing Synopsis
The String class is covered in this class and the powerful methods that go with it!
 

  Specification (very partial) of java.lang.String class
  1) < string > .length () - > int / /length of string
  ``cs1 exams are fun'' .length () = 18
 
  2) < string > .indexOf (< string >) - > int
  / /yields the leftmost occurene pos.
  ``frim fram sauce'' .indefOf ( ``fr'' ) - > 0
 
  3 a) < string > .substring (< int >) - > < String >
  Returns the substring from the pos specified by the parameter
  to the end of the string.
  ``Monday'' .substring (3) - > ``day''
 
  3 b) < string > .substring (< int >,  < int >) - > < String >
  Returns the substring from the pos of the first parameter to the
  pos one less than the second parameter.
  ``fired hand'' .substring (2,  7) - > ``red_h''
 
  4) < string > .equals (< string > - > < boolean >
  Compares one string to another and yields true or false.
 
  5) < string > .equalsIgnoreCase (< string >) - > < boolean >
  Same as 4) but ignores case
 
  6) < string > .compareTo (< string >) - > < int >
  Returns -
  0 - if the two strings are equal
  Something negative if the receiving string is alphabetically less than the parameter
  Something positive if the receiving string is alphabetically greater than the paramter
  Example:
  ``cat'' .compareTo ( ``bat'' ) - > positive value returned
  ``bat'' .compareTo ( ``bats'' ) - > negative value returned