8.3. The Character Class

 
[Page 261]

Chapter 8. Strings and Text I/O

Mayan God Shel, Mexico. Photographer: Philip Coblentz. Courtesy Brand X Pictures.

Objectives

  • To use the String class to process fixed strings ( §8.2).

  • To use the Character class to process a single character ( §8.3).

  • To use the StringBuilder / StringBuffer class to process flexible strings ( §8.4).

  • To know the differences between the String , StringBuilder , and StringBuffer classes ( § §8.2 “8.4).

  • To learn how to pass strings to the main method from the command line ( §8.5).

  • (Optional) To use the regular expressions to represent patterns for matching, replacing, and splitting strings ( §8.6).

  • To discover file properties, delete and rename files using the File class ( §8.7).

  • To write data to a file using the PrintWriter class ( §8.8.1).

  • To read data from a file using the Scanner class ( §8.8.2).

  • (Optional GUI) To add components to a frame ( §8.9).


[Page 262]

8.1. Introduction

Strings are used often in programming. A string is a sequence of characters. In many languages, strings are treated as arrays of characters , but in Java a string is an object. Java provides the String , StringBuilder , and StringBuffer classes for storing and processing strings.

In most cases, you use the String class to create strings. The String class is efficient for storing and processing strings, but strings created with the String class cannot be modified. The StringBuilder and StringBuffer classes enable you to create flexible strings that can be modified.

This chapter also introduces how to process command-line arguments to the main method and how to perform simple text input and output using the Scanner class and the PrintWriter class.

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net