Ics3u stringbuffer
This presentation is the property of its rightful owner.
Sponsored Links
1 / 11

ICS3U – StringBuffer PowerPoint PPT Presentation


  • 61 Views
  • Uploaded on
  • Presentation posted in: General

ICS3U – StringBuffer. Teacher: Mr. Ho Course URL: http://computerNHSS.wikispaces.com. Review of String. String is a special data type (or class) in Java E.g. String str1 = “Hello, I am a string”; Once str1 is assigned a value, its value cannot be changed. StringBuffer.

Download Presentation

ICS3U – StringBuffer

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Ics3u stringbuffer

ICS3U – StringBuffer

Teacher: Mr. Ho

Course URL: http://computerNHSS.wikispaces.com


Review of string

Review of String

  • String is a special data type (or class) in Java

  • E.g. String str1 = “Hello, I am a string”;

  • Once str1 is assigned a value, its value cannot be changed.


Stringbuffer

StringBuffer

  • Another special data type (or class) in Java

  • Like String, except that the value of StringBuffer can be changed.


Built in methods

Built-In Methods

  • StringBuffer sb = new StringBuffer(“Hello”);

  • sb.length(); // length of StringBuffer

  • sb.charAt(1); // getting a character

  • sb.insert(2, “ABC”); // inserting

  • sb.append(“DEF”); // appending

  • sb.reverse(); // reversing StringBuffer

  • String s = sb.toString(); // getting String


Sb length

sb.length()

In the main() method:

StringBuffer sb = new StringBuffer(“Hello”);

System.out.println(sb.length());

Output:

5


Sb charat 1

sb.charAt(1)

In the main() method:

StringBuffer sb = new StringBuffer(“Hello”);

System.out.println(sb.charAt(1));

Output:

e


Sb insert 2 abc

sb.insert(2, “ABC”)

In the main() method:

StringBuffer sb = new StringBuffer(“Hello”);

System.out.println(sb.insert(2, “ABC”));

Output:

HeABCllo


Sb append def

sb.append(“DEF”)

In the main() method:

StringBuffer sb = new StringBuffer(“Hello”);

System.out.println(sb.append(“DEF”));

Output:

HelloDEF


Sb reverse

sb.reverse()

In the main() method:

StringBuffer sb = new StringBuffer(“Hello”);

System.out.println(sb.reverse());

Output:

olleH


Sb tostring

sb.toString()

In the main() method:

StringBuffer sb = new StringBuffer(“Hello”);

String s = sb.toString();

System.out.println(s);

Output:

Hello


Classwork

Classwork

  • Go to http://computerNHSS.wikispaces.com

  • Download the classwork:

    • JBB_pg_18.pdf

    • JBB_pg_19.pdf

    • JBB_pg_22.pdf


  • Login