Docsity

Java Collections: Understanding Lists, Linked Lists, Stacks, and Queues, Slides of Applications of Computer Sciences

Partial preview of the text

Download Java Collections: Understanding Lists, Linked Lists, Stacks, and Queues and more Slides Applications of Computer Sciences in PDF only on Docsity!

Chapter 13:

Collections: List

Creation and Maintenance

Object-Oriented Program

Development Using Java: A

Class-Centered Approach

Objectives

  • The Collection Framework
  • Linked Lists
  • Stacks
  • Queues
  • Common Programming Errors

Objects and Records

  • In real-world applications data is stored in records
    • Data items in records are data fields
  • In Java, records are implemented as objects

Linked Lists (continued)

  • Special reference is provided for storing the location of the first object in a list
  • Last record in the list will always have a null value for next item reference
  • Creating a linked list:
    • Use Java Collection Framework’s LinkedList class
    • Can also create your own

Constructing Your Own

Linked List

  • Provide each record with at least one reference variable - Include in the data declaration section
  • Links can be used to loop through a complete list

When to Use an Array or

LinkedList Container

  • Array:
    • Use for a list of primitive data types or objects that do not have to be expanded or contracted
  • LinkedList
    • Use for a list of objects that can be grouped as an array but must be expanded or contracted