Set Value to String [] object [on hold]

I have this string that contain month. I want to save code of the month. Example if I saved month January, it will save code of the month "1". How do I do set the value of every month.

String [] month= {"January", "February", "March", "April", "May", "June", "July", "August", "September",
            "October", "November", "December"};

Use a Map instead of an array. The Map will have type Map<String, Integer> months. Put each of your months in the map with their corresponding value. When you need the value of each month, get it from the map by supplying the month name

You can use HashMap for that purpose if you want to have key-value pair structure.

HashMap<Integer,String> months=new HashMap<Integer,String>(); 
// similarly put other month 

If you would like to get value from hashmap by its key, you can use

String firstMonth = newMap.get(1);

0 Comment



Captcha image