如何在 java 上设置对象哈希图

how to set objeck hashmap on java

我有一个这样的模型 "sentence" :

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;
}

我想像这样在对象 "sentence" 上设置值哈希映射:

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));
         }
     }

但我在第

行有错误
sentence.setBobotChiSquare(token[j] , new Double(0,0));

有人能帮忙吗?

您的方法需要一个 HashMap 作为参数,但您传递了一个 String 和一个 double。您首先必须将它们放入 HashMap.