D4.11 – D4.14 Construct algorithms using the standard library collections included in JETS

A simple linked list created with one item in

Add more items

addFirst() – Adds the item to the start of the linked list

addLast() – Adds items to the end of the list

add (index, item to add)

Other Methods available

The exam will list the methods that are available but you should familiarize yourself with them in Java regardless

Stacks

Remember a stack is a LIFO (Last in First Out)

Queues

Since Queue is an interface you need to instantiate a concrete implementation of the interface in order to use it.

You can choose between the following Queue implementations in the Java Collections API:

  • java.util.LinkedList
  • java.util.PriorityQueue

LinkedList is a pretty standard queue implementation.

Iterators

An Iterator allows us to access each element in a collection.

An Iterator can do things that a foreach loop can’t. For example, you can remove elements from a collection while you’re iterating

The primary purpose of an iterator is to allow a user to process every element of a container while isolating the user from the internal structure of the container.

Here an Arraylist is created

An Iterator has been created for the list

Make sure you use this guide for your Paper 2 Exam