HashMap同时遍历key与value

遍历整体Object 使用entrySet
for(Iterator iter = hp.entrySet().iterator();iter.hasNext();){
    Map.Entry element = (Map.Entry)iter.next();
    Object strKey = element.getKey();
    Object strObj = element.getValue();
    }

遍历key  使用keySet
for(Iterator iter = hp.keySet().iterator();iter.hasNext();){
                        iter
    Object key = iterator.next();
    }
遍历value 使用values()
for(Iterator iter = hp.values().iterator();iter.hasNext();){
                        iter
    Object key = iterator.next();
    }

附加:
对文件夹中每个文件进行遍历
File file = new File("src/form/");  // 根目录
String[] filelist = file.list();    // 目录下的文件列表
  for (int i = 0; i < filelist.length; i++) {
        File fPatter = new File("src/form/" + filelist[i]);
        InputStreamReader readPatter = new InputStreamReader (new FileInputStream(fPatter),"UTF-8");
  }

你可能感兴趣的:(HP)