When compiling a short piece of java code I get a compilation note of having unsafe operations. I basically just was hoping for the concept of how to change my data structure that would make it safe.
The concept: I need to organize inputed strings into buckets based on their length, which could be arbitrary (although less than 80 chars).
The Code:
Map<Integer, List> buckets = new HashMap<Integer, List>();
if(!buckets.containsKey(length))
{
buckets.put(length,new Vector<wordValues>());
}
//Now add the temp to the bucket
buckets.get(length).add(new wordValues(temp));
And then I add the string to the list corresponding to its size.
What would be a better way to do this?
You mix raw and Generics List, try:
Map<Integer, List<wordValues>> buckets = new HashMap<Integer, List<wordValues>>();
Also, usually class names start with upper case, e.g. WordValues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With