Docsity

Strings - Business Application Programming - Lecture Slides, Slides of Applications of Computer Sciences

Partial preview of the text

Download Strings - Business Application Programming - Lecture Slides and more Slides Applications of Computer Sciences in PDF only on Docsity!

Strings

Chapter 7 Overview

Today’s Lesson Plan

  • Discuss labs, quizzes, and TDA topics (10 min)
    • Final is in-class next week!
  • Class Activities – covers Chapter 7 (120 min)
    • Discuss Strings and characters. (45 min)
    • Discuss String Processing. (45 min)
    • Discuss the StringBuffer class. (30 min)
  • Coding Exercises & break (90 min)
    • Code Ex 1 – p 375 – #7.2.15a & 15b
    • Code Ex 2 – p 541 – #10.2.11a
    • Code Ex 3 – p 542 – #10.2.14a & 14b Docsity.com

The String Class

  • A string literal is a sequence of characters enclosed in double quotation marks
  • A string value is created as an object of:
    • String or StringBuffer
  • The main difference between the two classes:
    • Strings created as String objects cannot be modified - StringBuffer objects can be modified

Creating a String

  • Syntax: String identifier = new String(string-value);

String identifier; identifier = new String(string-value);

String identifier = string-value;

Constructors

  • Instantiating an object is the process of using the new operator to create an object
  • The name of the constructor method must be the same name as the class
  • The String class provides nine different constructors for creating String objects

String I/O

  • Basic String Input and Output Methods

String Processing

  • Strings are manipulated using:
  • Standard String class methods
  • Character-at-a-time methods provided by the Character class

Other String Methods

  • The last position is always one less than the number of characters in the string
  • The charAt() method permits you to retrieve individual characters in a string
  • You can then convert these characters/elements charAt() returns using the Character class, as per the next slide!

The StringBuffer Class

(continued)

  • String class
    • Preferred class for displaying or comparing strings that tend to remain constant
  • StringBuffer class for strings that aren’t

constant!

  • Should be used for applications that require:
    • Individual character additions
    • Modifications Docsity.com