Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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


Download ppt "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."

Similar presentations


Ads by Google