Changing map key using enum on java

Posted: January 16, 2013 in web


public enum CarType {

	private final String type;
	CarType(String type){
		this.type = type;
	public String getType(){
		return type;
	public static Map<String, CarType> getMap{
		Map<String, CarType> hashMap = new LinkedHashMap<String, CarType>();
		for(CarType carType : CarType.values()){		
			hasMap.put(carType.type, carType);

		return hashMap;



public Map<String, CarType> getCarTypes(){
	Map<String, CarType> map = CarType.getMap();
	//need to change Truck label to Double Cab
		map.put("Double Cab", CarType.TRUCK);
	return map;




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s