ics3u stringbuffer n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
ICS3U – StringBuffer PowerPoint Presentation
Download Presentation
ICS3U – StringBuffer

Loading in 2 Seconds...

play fullscreen
1 / 11

ICS3U – StringBuffer - PowerPoint PPT Presentation


  • 101 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'ICS3U – StringBuffer' - judah


Download Now 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