| preferred AP College board partner for AP classes
AP Computer Science A/Unit 2: Using Objects
Start Practice TestPractice Test
Share
About Exam
medium Solved by 3 students
Java String Method Behavior
< Prev
Next >

Identify the attributes and behaviors of a class found in the libraries contained in an API.

A programmer is working with the String class and writes the following code:

String word = "PROGRAMMING";
int pos = word.indexOf("GRAM");
String result = word.substring(pos, pos + 4);
System.out.println(result);

Which of the following best describes what this code accomplishes?

A

It creates a new string by removing “GRAM” from the original string

B

It counts the number of characters between “GRAM” and the end of the string

C

It finds and extracts the substring “GRAM” from the original string

D

It replaces all occurrences of “GRAM” with a 4-character substring

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy