Please enable JavaScript to use CodeHS

Chapter 2

Using Objects

2.7 String Methods

APIs, Libraries, and Documentation

Concatenating Strings with Reference Data Types

Object Concatenation

String Index Values

Other Useful String Methods

Bigger Strings?

Chopping Strings

Check Your Understanding

  1. Incorrect Correct No Answer was selected Invalid Answer

Exercise: toString for Plants

Vocabulary

Term Definition
String(String str) constructor Constructs a new String object that represents the same sequence of characters as str
int length() Returns the number of characters in a String object
String substring(int from, int to) Returns the substring beginning at index from and ending at index to − 1
String substring(int from) Returns substring(from, length())
IndexOutOfBoundsException A String object has index values from 0 to length – 1. Attempting to access indices outside this range will result in this error.
int indexOf(String str) Returns the index of the first occurrence of str; returns -1 if not found
int compareTo(String other) Returns a value < 0 if this is less than other; returns zero if this is equal to other; returns a value > 0 if this is greater than other
Application Programming Interfaces APIs and libraries simplify complex programming tasks by providing sets of clearly defined methods of communication among various computing components.
Documentation Documentation is the reference for how to use different methods and classes