I am reading a map from config and based upon if the key is available in map or not , i am reading the key value or default value . I want to know which is better and cleaner way fo writing among the below two just for knowledge purpose
String sFolder;
Map<String, String> sFolderMap = Config.findMap("FolderMap");
if(!sFolderMap.containsKey(subject)) {
sFolder = sFolderMap.get("DEFAULT");
} else {
sFolder = sFolderMap.get(subject);
}
// perform some operation based on value of sFolder
String sFolder;
Map<String, String> sFolderMap = Config.findMap("FolderMap");
sFolder = sFolderMap.get("DEFAULT");
if(sFolderMap.containsKey(subject)) {
sFolder = sFolderMap.get(subject);
}
// perform some operation based on value of sFolder
Aucun commentaire:
Enregistrer un commentaire