Question: Long story short, the snippets below is about converting the texted month to numbered month (ex, Jan -> 1). There's no error but in the end I keep getting 0 as the result of m. Where's the problem?

```
//date1s[] is the result of splitting date1 by spaces (date1 = 1 Jan 2012)
m = convertMonth(date1s[1]); //date1s[1] contains the Month; date1s[0] the date and date1s[2] the year

public int convertMonth(String monw) {
        int x = 0;
        if (monw == "Jan") {
            x = 1;
        }
        else if (monw == "Feb") {
            x = 2;
        } 
        else if (monw == "Mar") {
            x = 3;
        } 
        else if (monw == "Apr") {
            x = 4;
        } 
        else if (monw == "May") {
            x = 5;
        } 
        else if (monw == "Jun") {
            x = 6;
        } 
        else if (monw == "Jul") {
            x = 7;
        } 
        else if (monw == "Aug") {
            x = 8;
        } 
        else if (monw == "Sep") {
            x = 9;
        } 
        else if (monw == "Oct") {
            x = 10;
        } 
        else if (monw == "Nov") {
            x = 11;
        } 
        else if (monw == "Dec") {
            x = 12;
        }
        return x;
}    

```

Answer: 
Your problem of string comparision is very well explained by others so I will not rewrite that. Other than that...

In your case, *if your month names are contant*, it will be *better* to use a `Map<String,Integer>` of month names and value or `Enum` having month names. It will omit your long `if...else..if...else` conditions.

---

Enum example:

```
public enum Month {
    Jan,
    Feb,
    Mar,
    Apr,
    // ...
    Dec
}    
public int toMonthInt(String input) {
    return Month.valueOf(input).ordinal() + 1; // +1 because you want Month value to start with 1.
}

```

---

Map example:

```
    Map<String, Integer> map = new HashMap<String, Integer>();
    map.put("Jan", 1);
    map.put("Feb", 2);
    map.put("Mar", 3);
    map.put("Apr", 4);
    // ...
    map.put("Dec", 12);
    System.out.println(map.get("Jan"));

```
```
if ("Jan".equals (monw))
{  
     x = 1;
}

```