Arrays of Strings

From CompSciWiki
Revision as of 11:47, 27 November 2007 by JonathanM (Talk | contribs)

Jump to: navigation, search

COMP 1010 Home > Arrays of Strings


Introduction

This section is all about arrays of Strings. This section assumes that you have already read the chapter on Strings and the chapter on Arrays. In addition to teaching you the basics of arrays with Strings, I'll talk about indexing errors (such as off-by-one errors) and how infuriating they can be when using arrays of Strings.

   

{{{Body}}}

What Are Arrays of Strings?

As said in the introduction, we are mainly assuming that you know what an array is, and what a String is. As a quick refresher, an array is a contiguous group of some data type, and a String is effectively (if not actually) an array of characters. So, where is this going?

An array of Strings is your first look at the more general concept of multi-dimensional arrays. An array of Strings is a contiguous group of Strings, and each String is a contiguous group of characters. An array of strings is really a two-dimensional array: An array of arrays of characters. Even though you don't actually use Strings as arrays (for example, you get individual characters with charAt() instead of just an index), much of what you learn here will apply to real two-dimensional arrays. But that's later.

As an aside, you could go crazy with this and make an array of arrays of Strings, which would be an array of arrays of arrays of characters, but you probably will never have to deal with arrays of more than two dimensions in any of your assignments. Be glad -- Multidimensional arrays are a real pain in the neck.

do you have stairs in your house

AAAAAAAAAAAAAH