【转】Android遍历Map的两种常用方法

转载自: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的查找速度。

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);
}

参考链接:

Java中常用的正则表达式判断,如IP地址、电话号码、邮箱等

java中正则表达式匹配ip地址的写法

Windows可清理文件夹

日志文件

C:\Windows\Logs\CBS

临时文件

C:\Windows\Temp
C:\Users\Administrator\AppData\Local\Temp

应用历史版本

C:\Users\Administrator\AppData\Local\Postman
C:\Users\Administrator\AppData\Local\kingsoft\WPS Office

阿里云盘缓存

C:\Users\Administrator\AppData\Roaming\aDrive\Partitions\adrive\blob_storage
C:\Users\Administrator\AppData\Roaming\aDrive\Partitions\adrive\Cache

抱歉,Xposed真的可以为所欲为

抱歉,Xposed真的可以为所欲为——1.基础知识储备

抱歉,Xposed真的可以为所欲为——2.改为OV机型流畅玩耍高帧率王者农药

抱歉,Xposed真的可以为所欲为——3.微信运动占领封面出售广告位

抱歉,Xposed真的可以为所欲为——4.猜拳投骰子你能赢算我输

抱歉,Xposed真的可以为所欲为——5.我自己刷的Xposed凭什么不给我用

抱歉,Xposed真的可以为所欲为——6.你的表白撤不回了