Search code examples
javaobjecthashmapsetvalue

how to set objeck hashmap on java


i have a model "sentence" like this :

String kalimat;
HashMap<String, Double> bobotChiSquare = new HashMap<>();
HashMap<String, Double> bobotTFIDF = new HashMap<>();
HashMap<String, Integer> countTandaBaca = new HashMap<>();
public HashMap<String, Double> getBobotChiSquare() {
    return bobotChiSquare;
}

public void setBobotChiSquare(HashMap<String, Double> bobotChiSquare) {
    this.bobotChiSquare = bobotChiSquare;
}

and i want to set value hashmap on object "sentence" like this :

ArrayList <Sentence> listToken = new ArrayList<>();
     Sentence sentence = null;
     for (int i = 0; i < input.size(); i++) {
         sentence.setKalimat(input.get(i));
         String[] token = input.get(i).split(" ");
         for (int j = 0; j < token.length; j++) {
             sentence.setBobotChiSquare(token[j] , new Double(0,0));
         }
     }

but i have an error in line

sentence.setBobotChiSquare(token[j] , new Double(0,0));

Can anyone help?


Solution

  • Your method expects a HashMap as parameter but your passing a String and a double. You first have to put them into a HashMap.