首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Algorithm - 一种从properties中依据value找key的方法

2012-08-21 
Algorithm - 一种从properties中根据value找key的方法Constraints:?1. relation of key and value is one-

Algorithm - 一种从properties中根据value找key的方法

Constraints:

?1. relation of key and value is one-to-one, and both unique.

?2. key and value is both String.

?

?

public String getKey(String value) {if (ht == null)ht = new Hashtable<String, String>();if (Checker.isNotNull(entrySet())&& Checker.isNotNull(entrySet().iterator())) {Set<Map.Entry<Object, Object>> set = this.entrySet();Iterator<Map.Entry<Object, Object>> iter = set.iterator();while (iter.hasNext()) {Map.Entry<Object, Object> entry = iter.next();if (entry.getKey() instanceof String&& entry.getValue() instanceof String) {String k = (String) entry.getKey();String v = (String) entry.getValue();ht.put(v, k);}}}return ht.get(value);}

热点排行