0

Im having problems when trying to initialize the variable:

Map<Sentence, Float>[] vectorValueSentences; // this is ok

/* but this is not */ vectorValueSentences = new HashMap<Sentence, Float>()[100];

I search on what to do but i didnt find any. I read that the object to be initialize has to be static but i dont find a way to declare the Map static.

Thank you for your help!

5
  • 1
    Can you include a fuller snippet? It's hard to understand without some more context. Commented Oct 10, 2015 at 19:21
  • If vectorValuesSentences is not declared before calling the line vectorValueSentences = new HashMap<Sentence, Float>()[100];, obviously its wrong Commented Oct 10, 2015 at 19:22
  • Because of how generics in Java work, you cannot directly create an array of a generic type (such as Map<Object, Object>[]). Or You are trying to do something else? More in: stackoverflow.com/questions/14917375/… Commented Oct 10, 2015 at 19:25
  • 2
    You should consider using a List of Maps. List<Map<Sentence, Float>> vectorValueSentences = new ArrayList<Map<Sentence, Float>>(); Commented Oct 10, 2015 at 19:26
  • Thank you guys! it was my first question here and solve it so quickly. Hope i can help in this community from now on Commented Oct 10, 2015 at 22:58

1 Answer 1

1
    HashMap<Sentence, Float>[] vectorValueSentences = new HashMap[100];
Sign up to request clarification or add additional context in comments.

1 Comment

Wooooooow, thank you! I can believe it was so simple and yet couldn't find it anywhere. Deepak Marathe, you are great :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.