1.set
当判断条件只要满足多种状态中的一种,判断中查找
#include
static std::set mstatus {
status::sleep,
status::run,
status::suspend,
status::unknow,
};
status current = ?
mstatus.find(current) != mstatus.end()
在mstatus中去查找,找不到返回最后一位的值end().
2.map
根据key去找寻相匹配的值
#include
private static HashMap<String,Integer> flashValue = new HashMap<String,Integer>();
static{
for(int i = 0; i < str.length; ++i) {
flashValue.put(str[i],i+1);
}
}
可以先在这个之前使用containsKey() 方法检查 hashMap 中是否存在指定的 key 对应的映射关系,
如果 hashMap 中存在指定的 key 对应的映射关系返回 true,否则返回 false。