> For the complete documentation index, see [llms.txt](https://www.computersciencea.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.computersciencea.com/unit-1-using-objects-and-methods/1.15-string-manipulation.md).

# 1.15 String Manipulation

**Suggested Skills:** 2.C, 3.C, 4.A, 4.B

**LO 1.15.A** — Develop code to create string objects and determine the result of creating and combining strings.

* **1.15.A.1** — A `String` object represents a sequence of characters and can be created by using a string literal or by calling the `String` class constructor.
* **1.15.A.2** — The `String` class is part of the `java.lang` package. Classes in the `java.lang` package are available by default.
* **1.15.A.3** — A `String` object is **immutable**, meaning once a `String` object is created, its attributes cannot be changed. Methods called on a `String` object do not change the content of the `String` object.
* **1.15.A.4** — Two `String` objects can be **concatenated** together or combined using the `+` or `+=` operator, resulting in a new `String` object. A primitive value can be concatenated with a `String` object. This causes the implicit conversion of the primitive value to a `String` object.
* **1.15.A.5** — A `String` object can be concatenated with any object, which implicitly calls the object's `toString` method (a behavior guaranteed to exist by the inheritance relationship every class has with the `Object` class). An object's `toString` method returns a string value representing the object. Subclasses of `Object` often override the `toString` method with class-specific implementation. **Method overriding** occurs when a public method in a subclass has the same method signature as a public method in the superclass, but the behavior of the method is specific to the subclass.
  * ❌ **EXCLUSION** — Overriding the `toString` method of a class is outside scope.

**LO 1.15.B** — Develop code to call methods on string objects and determine the result of calling these methods.

* **1.15.B.1** — A `String` object has index values from `0` to one less than the length of the string. Attempting to access indices outside this range will result in a `StringIndexOutOfBoundsException`.
* **1.15.B.2** — The following `String` methods are part of the Java Quick Reference:
  * `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())`.
  * `int indexOf(String str)` — returns the index of the first occurrence of `str`; returns `-1` if not found.
  * `boolean equals(Object other)` — returns `true` if `this` corresponds to the same sequence of characters as `other`; returns `false` otherwise.
  * `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`. Strings are ordered based upon the alphabet.
  * ❌ **EXCLUSION** — Using the `equals` method to compare one `String` object with an object of a type other than `String` is outside scope.
* **1.15.B.3** — A string identical to the single element substring at position `index` can be created by calling `substring(index, index + 1)`.

> 📘 **Lab:** After completing this unit, students will have covered all of the necessary content for the **Receipt Lab**.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://www.computersciencea.com/unit-1-using-objects-and-methods/1.15-string-manipulation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
