Blakes 21 Days Chapter 08 Document

Day 8, Data Structures

Moving Beyond Arrays

Java Structures


Bit Sets

Figure 8.1 The Organization of a bit set.

Figure 8.1 The Organization of a bit set.
Index 0 1 2 3
Value Boolean0 Boolean1 Boolean2 Boolean3

Listing 8.1

The Explanation

Figure 8.2 Trying out the BitSet data structure

Array Lists

Looping Through Data Structures

Second Program

Listing 8.2

The Explanantion

Figure 8.3 goes here


Figure 8.4 The Organization of a Stack
Position from top    
0 Element3 TOP
1 Element2  
2 Element1  
3 Element0 BOTTOM


Figure 8.5 The Organization
of a key-mapped data structure,
Key0 -------> Element0
Key1 -------> Element1
Key2 -------> Element2
Key3 -------> Element3

Hash Maps

The Third Program

Listing 8.3

Figure 8.6 Storing comic book values in a hash map.

The Explanation


The Fourth Program

Listing 8.4 - The full Text of



Q & A

Quiz - Questions

  1. Which of the following kinds of data cannot be stored in a hash map ?
    1. String
    2. int
    3. Both can be stored in a map.
  2. An array list is created, and three strings, "Tinker", "Evers", and "Chance", are added to it. The method remove("Evers") is called. Which of the following ArrayList methods retrieves the string "Chance" ?
    1. get(1);
    2. get(2);
    3. get("Chance");
  3. Which of these classes implements the Map interface ?
    1. Stack
    2. HashMap
    3. BitSet


  1. C. In the past versions of Java, to store primitive types such as int in a map, objects had to be used to represent their values (such as Integer for integers).
  2. A. The index numbers of each item in an array list can change as items are added or removed.
  3. B. HashMap implements the interface, as does a similar class called Hashable.

Certification Practice

  1. What will be the output of this application ?
    1. -1
    2. 17
    3. 34
    4. 136