Tyler Tallman wrote:I have different sets mapped to different keys in a map. I want to find the set with the most elements, but when I try to do map.get(i).size() > anotherValue, it tells me that it cannot cast java.lang.String to java.lang.Integer. Why does it tell me this?
Sounds like anotherValue is a String. Hard to say for sure though without your code. Of course, if you look closely at the error message and at the code it's complaining about, it should become obvious.
I thought that if I was trying to get the size of a value, then it would return me a number, not a string.
If you get the size of a collection, it will be an int. So either:
A) That side of the comparison is not the size of a collection, or is doing something else with a String when it should be using an int.
B) The other side of the comparison is a String.
How am I supposed to find the largest set in my map?
By comparing ints to ints, not to Strings.
Bottom line: The error messages don't lie. So rather than taking the approach, "What's wrong with Java? Why is it complaining about my perfect code?" you should instead take the approach, "What's wrong with my code? Which of my assumptions were wrong?"