Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
 
Class Notes

Monday November 6 , 2000
 
Tonight we were introduced to some String Processing through a specification (very partial) of java.lang.String class. 

1)    < String > .length ()    -- >    < int >
2)    < String > .indexOf (< String >)    -- >    < int >

  • the < int > result of:   ``frim fram sauce''.indexOf (``fr'') would be 0
  • the < int > result of:   ``frim fram sauce''.indexOf (``fra'') would be 5
3 a)    < String > .substring (< int >)    -- >    < String >
  • returns the substring from the position specified by the parameter to the end of the string.   Example:   result of ``Monday''.substring (3) would be ``day''
3 b)    < String > .substring (< int >,  < int >)    -- >    < String >
  • returns the substring from the position specified by the parameter to the position one less than the second parameter.   Example:   result of ``tired hand''.substring (2,  7) would be ``red h''
4)    < String > .equals (< String >)    -- >    < boolean >
  • ``cat''.equals (``dog'') - > false
  • ``cat''.equals (``cat'') - > true
  • ``cat''.equals (``Cat'') - > false
5)    < String > .equalsIgnoreCase (< String >)
6)    < String > .compareTo (< String >)    -- >    < int > returns....
  • 0 if the two strings are equal
  • something negative if the receiving is alphabetically less than the parameter
  • something positive if the receiving is alphabetically greater than the parameter
  • Example:   ``cat''.compareTo (``bat'') - > greater than
  • Example:   ``bat''.compareTo (``bats'') - > something negative