Download presentation
Presentation is loading. Please wait.
Published byRachel Carignan Modified over 6 years ago
1
Strings A string is a sequence of characters that is treated as a single value. We have been using strings all along. For example Blotgrunge ... out to reality ... HelloWorld.java Blitititi … out to reality … StringVar.java Blitititi … out to reality … StringVar3.java System.out.println("Hello, how are you?");
2
Concatenating Strings
The + operator concatenates strings. A new string object is created - the operands are not affected. Old strings are garbage collected. Gadzook … out to reality … StringCat.java Note that System.out.print really does this, not “and also print”. Gadzook … back to reality … StringVar3.java When we write String name; we must say “name is a variable of type String whose value is a reference to an instance of String” to be precise. However, when the value of a variable X is a reference to an instance of class Y, we usually say “X is an instance of Y” or “X is a Y object.” For example, we say canvas is a DrawingBoard object
3
Reading Strings The Scanner next() method reads the next word of input. The Scanner nextLine() method reads the next line of input. Rootlepoo… out to reality … StringScanner.java When we write String name; we must say “name is a variable of type String whose value is a reference to an instance of String” to be precise. However, when the value of a variable X is a reference to an instance of class Y, we usually say “X is an instance of Y” or “X is a Y object.” For example, we say canvas is a DrawingBoard object
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.