Please enable JavaScript to use CodeHS

AP Computer Science A (Mocha)

Lesson 3.6 Strings and Characters

Description

In this lesson, we’ll examine the similarities and differences between the String class and the char primitive type. Strings are simply sequences of chars.

We also learn that all char values have a corresponding int value. chars are actually stored as numbers! For example, 65 corresponds to ‘A’, 66 corresponds to ‘B’, and so on. We’ll learn about special characters like tabs, quotes, and new lines, and how to store and print these special characters using escape sequences like ‘\n’

Lastly, we learn about the Character class. The Character class provides several useful methods that allow us to manipulate and get information about char values.


Objective

Students will be able to…

  • Explain the relationship between Strings and chars
  • Explain the difference between the primitive type char and the class Character
  • Convert char values to int values using casting
  • Convert int values to char values using casting
  • Print out special characters like quotes and new lines using escape sequence chars (such as ‘\n’ and ‘\”’)
  • Utilize the static methods of the Character class to manipulate get information about char values