This question already has an answer here:
- How do I compare strings in Java? 23 answers
I am having a hashMap which stores my values like that:
{10997=Event [Numb=0007449001, date=07.02.2008], 10998=Event [Numb=0007449001, date=08.04.2008], ...
As you can see the key is a integer and the value is an Event Object which has a numeric value and a date, which is saved as a String.
I want to compare the numeric value of the map to another value with an if statment.
I tried:
if(numericVal==eventMap.get(i).toString()) {
However that does not really work. How to get the value easily out of the HashMap and of the Object?
I appreciate your answer!
UPDATE
By easily I mean performance orientated, because I have to process a lot
of values.
first off; do not compare String
s with ==
use equalsIgnoreCase()
instead (or just equals()
if the casing matters)
second; consider giving your Event
a compareTo()
and while you are at it an equals()
and a hashCode()
.
Once you got the components in place and why they should be there, you'll realize what you want to do is possible in a much more elegant way.