PrepGo

AP Computer Science Principles Practice Quiz: Strings

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Test your understanding with short quizzes. This quiz has 9 questions to check your progress.

Question 1 of 9

Which of the following best describes the process of string concatenation?

All Questions (9)

Which of the following best describes the process of string concatenation?

A) Finding a part of an existing string.

B) Joining two or more strings together end-to-end.

C) Evaluating a mathematical value from a string.

D) Removing characters from a string.

Correct Answer: B

The provided content defines string concatenation as the process that "joins together two or more strings end-to-end to make a new string."

What is the correct term for a part of an existing string?

A) Concatenation

B) Expression

C) Substring

D) Manipulation

Correct Answer: C

The provided content explicitly states, "A substring is part of an existing string."

Consider an expression that performs string concatenation on "Hello" and "World", in that order. What is the resulting new string?

A) HelloWorld

B) WorldHello

C) Hello World

D) Hello

Correct Answer: A

String concatenation joins strings end-to-end. The string "World" is placed immediately after the string "Hello", with no spaces added, resulting in "HelloWorld".

Given the string "concatenation", which of the following is a valid substring?

A) cat ion

B) conic

C) nation

D) tent

Correct Answer: C

A substring is a part of an existing string. The sequence of characters "nation" appears contiguously within "concate**nation**". The other options contain characters or sequences not found in the original string.

Evaluate the following string manipulation expression, which concatenates three strings in order: `"key"`, `"board"`, and `"ist"`.

A) key board ist

B) keyboardist

C) istkeyboard

D) keyist

Correct Answer: B

The expression involves joining three strings end-to-end. "key" is joined with "board" to make "keyboard", which is then joined with "ist" to make the final string "keyboardist".

A string variable `prefix` holds the value "sub". If an expression concatenates `prefix` with the string "marine", what is the resulting string?

A) sub marine

B) marinesub

C) submarine

D) sub

Correct Answer: C

The expression joins the value of `prefix` ("sub") with "marine" end-to-end. This manipulation creates the new string "submarine".

Let string `s1` be "note" and string `s2` be "book". A new string `s3` is created by concatenating `s1` and `s2`. Which of the following is NOT a substring of `s3`?

A) notebook

B) oteb

C) book

D) e b

Correct Answer: D

Concatenating `s1` ("note") and `s2` ("book") results in the new string `s3` being "notebook". "notebook", "oteb", and "book" are all parts of "notebook" and are therefore substrings. The option "e b" contains a space, which is not present in the final string, so it is not a substring.

Consider two different, non-empty strings, `strA` and `strB`. Let `result1` be the outcome of concatenating `strA` with `strB`. Let `result2` be the outcome of concatenating `strB` with `strA`. Based on the definition of string concatenation, which statement is always true?

A) `result1` is always identical to `result2`.

B) `result1` is a substring of `result2`.

C) `strA` is a substring of `result2`.

D) `result1` is generally different from `result2`.

Correct Answer: D

Concatenation joins strings end-to-end in a specific order. For example, joining "A" and "B" gives "AB", while joining "B" and "A" gives "BA". Since the order matters and the strings are different, the results are generally different.

Consider the following sequence of string manipulations: 1. A new string, `word`, is created by concatenating "sub" and "string". 2. Another new string, `phrase`, is created by concatenating "A " and `word`. Which of the following is a substring of the final `phrase`?

A) substring

B) Astring

C) sub string

D) A sub

Correct Answer: D

In step 1, `word` becomes "substring". In step 2, `phrase` is created by joining "A " and "substring", resulting in "A substring". "A sub" is a part of this final string ("**A sub**string") and is therefore a valid substring. Option A is also a substring, but this question asks to identify *a* substring, and all options must be evaluated. Option D correctly identifies a part of the final, concatenated string.