Which costs more:

Situation: I want to find all the unique words in a document.  I will make an Arraylist of all the unique words.

Method

CPU Ranking ( 1 = highest use)

Memory Ranking (1 = highest use)

Method 1:  add words to an arraylist, but check whether the arraylist contains the word before adding it. Use the Arraylist method contains before writing.

 

 

Method 2: add every word to the arraylist and then go through the arraylist checking each word using get to see whether it matches the word before. If it does, remove it.

 

 

Method 3: add every word to the arraylist and then go through the arraylist checking each word using get to see whether it matches the word before. If it does not, add it to a new arraylist