Algorithms and Data Structures in an Object-Oriented Framework (“ADSOOF”)
Code for “Collections Framework” section
List
(as defined in Java's Collections Framework) whose
base type implements Comparable
.
ListOps
to find the highest
integer in an arrayList of integers.
ListOps
to find the string
from a LinkedList (as defined in Java's Collection framework) of
strings, which is the last alphabetically of all the strings in it.
HashSet
of strings
(duplicates disappear, and they do not appear to be stored in any order).
HashSet
of strings
(duplicates disappear, and they appear to be stored in alphabetical order).
TreeSet
using an
Iterator
generated from the TreeSet
TreeSet
using a for-each loop.
TreeSet
which stores strings in
order of length, adding words to it, and going through it using a
for-each loop. But trying to add a word of the same length as a word already
added causes nothing to happen.
TreeSet
which stores strings in
order of length, and unlike TreeSet3
, doesn't regard different words
of the same length as duplicates.
Comparator
object used to create the
TreeSet
object in TreeSetPrint3
.
Comparator
object used to create the
TreeSet
object in TreeSetPrint4
.
Comparator
object which orders strings
according to their Scrabble score.
Collection
: one which returns the biggest item from the
collection in terms of the natural order of its base type, and one
which returns the biggest item from the collection as given by a
Comparator
object argument.
CollectionOps
with a Comparator
object as defined by LengthComparer
as its second argument.
Comparator
object.
Longest1
, with the
use of an anonymous class to define the Comparator
object
this time directly as a method argument rather than first referenced tbrough
a variable.
Longest1
, removing
another variable by (this time over-complex) embedding of structures.
Longest2
, but uses the
max
method from Java's Collections
class
rather than our own static method from CollectionOps
.
CollectionOps
with a
Comparator
object as defined by Scrabble
as its second
argument.
max
method from Java's
Collections framework, with a Comparator
object as defined
by Scrabble.java as its second argument.
BestScrabble2
, but shows the
use of an anonymous class to define the Comparator
object.
Scanner
object to read string/integer pair
data from a file and store it in a Java Map
object.
Marks
.
headSet
used to create a view
of a set with only those elements less than a specified element.
subList
used to create a
view of a list with only those elements between two specified indexes two specified indexes.
asList
in Java's class
Arrays
used to create a view of an array as a List
.
List
which is a view of an array cannot be changed
in length.
List
which is a view of an array can be changed
and the change is seen in the array, providing the length stays the same.
Comparator
as an argument.
Last modified: 19 July 2019