© Doug Winnie 2021
D. WinnieEssential Java for AP CompScihttps://doi.org/10.1007/978-1-4842-6183-5_43

43. Strings as Collections

Doug Winnie1  
(1)
Mission Hills, KS, USA
 

Strings are much more robust than they appear to be. They have several properties and capabilities that you can use methods to unlock to manipulate and manage contents of strings. These include finding the length of the string, extracting a specific character from a string, comparing strings, and pulling out a substring out of a larger string.

Creating Strings Using the String Class

Creating a string requires using the String class. Because we are using a class vs. a primitive as the type, we need to use the new keyword for the string:
String s = new String();
s = "Doug";

Getting a String ...

Get Essential Java for AP CompSci: From Programming to Computer Science now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.