Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Chapter 3: Design and Implementation

Section 3.5 Java

Summary: Let's rewrite these stuff in Java!

Exercise 3-4

Revise the Java version of markov to use an array instead of a Vector for the prefix in the State class.

Answer: An array makes more sense than Vector, because the size is fixed and known when the object is instantiated. Therefore, we don't need data struct that can grow and shrink dinamically.

Changes applied in this commit.

BONUS: Refactor the Java code to use up-to-data structures and practices:

  • Generics - Map<Prefix, Vector<String>> instead of Hashtable
  • Remove use of deprecated constructor of StreamTokenizer
  • Static constructor, instead of constructors with fields that differ from the fields of the class

Changes applied in this commit.