Java - Initialize a HashMap of HashMaps

前端 未结 4 1692
小蘑菇
小蘑菇 2020-12-17 15:52

I am new to java and practicing by creating a simplistic NaiveBayes classifier. I am still new to object instantiation, and wonder what to do to initialize a HashMap of Has

4条回答
  •  萌比男神i
    2020-12-17 16:16

    Yes, you need to initialize it.

    class_feature_counts = new HashMap>();
    

    When you want to add a value to class_feature_counts, you need to instantiate it too:

    HashMap val = new HashMap();
    // Do what you want to do with val
    class_feature_counts.put("myKey", val);
    

提交回复
热议问题