Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Unsafe Operations

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?

like image 747
user1620902 Avatar asked Aug 07 '26 12:08

user1620902


1 Answers

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.

like image 64
MByD Avatar answered Aug 09 '26 03:08

MByD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!