Question: Write an add method with the following signature: public void add(HashMap map, String lyricWord, int wordPosition) This method will determine if the given lyric word

Write an add method with the following signature:

public void add(HashMap> map, String lyricWord, int wordPosition)

This method will determine if the given lyric word is in the map. If the word is not in the map, then a mapping is added that maps that word to a list containing the position of the word in the lyric. If the word is already in the map, then its word position is added to the list of word positions for this word. Do not create a new mapping if the lyric word is already in the map. Use the one that is already there and just update its list. Remember to negate the word position if the word is at the end of a line in the lyrics.

I have this so far , However I am not sure on how to update the Arraylist vector in the hashmap because it is in a static context :

public static void add(HashMap> map, String lyricWord, int wordPosition) {

if( map.containsValue(lyricWord) == true){

map.putAll(lyricWord , // I dont know how to update(add) the vector with new word position , i tried the add function but it didnt work.....

}else{

map.put(lyricWord , new ArrayList(wordPosition));

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!