【转】Android遍历Map的两种常用方法
Map一般用来保存具有映射关系的数据,Map里保存着两组数据:key(键)和value(值),它们可以是任何引用类型的数据,但key不能重复。所以通过指定的key就可以取出对应的value。
遍历方式一、当键和值都需要用到时所采用的方法。
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
遍历方式二、当只使用键或者值时所采用的方法。
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
//遍历map中的键
for (Integer key : map.keySet()) {
System.out.println("Key = " + key);
}
//遍历map中的值
for (Integer value : map.values()) {
System.out.println("Value = " + value);
}
根据具体的使用场景选择特定的遍历方法可以加快map的查找速度。
WebSocket 在线测试
JAVA中正则表达式匹配IP地址的写法
private boolean isIP(String ip) {
if (ip == null || "".equals(ip)) {
return false;
}
String regex = "((25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)\\.){3}"
+ "(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)$";
return ip.matches(regex);
}
参考链接:
Android LocalBroadcast(本地广播)
Windows可清理文件夹
临时文件
%WINDIR%\Temp
%HOMEPATH%\AppData\Local\Temp
应用历史版本
%HOMEPATH%\.lingma\bin
%HOMEPATH%\AppData\Local\Postman
%HOMEPATH%\AppData\Local\kingsoft\WPS Office
阿里云盘缓存
%HOMEPATH%\AppData\Roaming\aDrive\Partitions\adrive\blob_storage
%HOMEPATH%\AppData\Roaming\aDrive\Partitions\adrive\Cache