2013년 12월 12일 목요일

java foreach 활용


  • eclipse 에서 foreach 타이핑 후  ctrl+space.
    Map<String, Object> params = new HashMap<String, Object>();
       for (String key : params.keySet()) {
            logger.debug("Key : {} -> Value : {}", key, params.get(key));
        }  
    
    List<String> args
    for (String arg : args) {
     result.append(" ").append(arg);
    }
    
    Cookie[] cookies = request.getCookies();
    for (Cookie cookie : cookies) {
     cookie.setMaxAge(0);
    }
    
    List<ServerList> monitoringServers = null;
    for (ServerList serverList : monitoringServers) {
     params.put("ip", serverList.getIp());
    }
    
    List<Entry> entries = staticModel.getEntries();
    for (Iterator<Entry> it = entries.iterator(); it.hasNext();) {
     Entry entry = it.next();
     if (entry.getMetadata().getProduct().equals(String.valueOf(projectId))) {
      it.remove();
     }
    }
    
    

댓글 없음:

댓글 쓰기