LECTURE OCTOBER 27 2004 ASSIGNMENTS Today 6:00 PM Assignment 3 Design Fri 10/29 CodeLab #8 COMPARING STRINGS What? - compareTo method How? - String instance method - argument: another String - returns an int - 0 if they are equal - a negative number if the argument is less than the instance - a positive number if the argument is greater than the instance - the exact numerical value depends on the relative Unicode lexicographic order STRING MANIPULATION What? - immutability of Strings How? - none of our methods can directly alter a string object Why? - makes memory allocation more efficient - lets us treat Strings as primitives What? - *string manipulation* How? - In Java, StringBuffer class - can directly alter the value of a StringBuffer What? - creating new instances of StringBuffer How? - must explicitly use the reserved word new - constructor takes a single String argument - changes do not affect original constructor argument What? - setCharAt method How? - StringBuffer instance method - first argument: int character position - second argument: char new value of that position What? - append method How? - StringBuffer instance method - argument: any primitive - concatenates the argument to the StringBuffer What? - append versus concatenation How? - may be used implicitly by the compiler for concatenation - more efficient than concatenation because avoids creating temporary variables