CS 1410 Lecture 5: Scanners and Object Intro
Document Summary
Scanner; pre-written class, create a scanner object to use: new keyword creates objects. System. in corresponds to characters from the keyboard: scanner nameofscanner = new scanner(system. in), must import scanner class. Or type import java. util. scanner; between the package and class headers. String; class, object: string s, s = hello . Don"t need to use new keyword with strings, using is allowed, since. Strings are commonly made this is a feature of java: strings are objects like scanners. Methods need a specific object to work on: example; in. nextint(); doesn"t specify which scanner is used in. nextint(); in. next(); in. nextline(); To close a scanner object use in. close(): closes a file or keyboard use. //counts the number of characters in the string. Boolean comparestrings = s. equals(otherstring): compares if strings are equal. If using == sign, the comparison is if they are the same object. Using . equals(), the contents of the objects are compared.