title: Find average using java 8 streams
body: <p>Am new to java 8 and still in learning phase. I have to write the below logic using java 8. I have an Json Array data and my json structure is as below.</p>
  
  <pre><code>{"list":[{"core":{"min":281.556,"max":286.67,"top":972.73},"dt":"2017-02-16 12:00:00"},{"core":{"min":281.821,"max":285.66,"top":970.91},"dt":"2017-02-16 15:00:00"},{"core":{"min":274.498,"max":277.05,"top":970.44},"dt":"2017-02-16 18:00:00"},{"core":{"min":271.503,"max":272.78,"top":969.32},"dt":"2017-02-16 21:00:00"}]}
  </code></pre>
  
  <p>This jsonArray will have around 100 jsonObject in it with data for every 3 hours. I actually need to find the average of min with max separately and average of top separately using java 8 stream or using other java 8 features. Another criteria is min and max average should be based on day or night. if dt contains like 06:00 or 09:00 or 12:00 or 15:00, it should be dayavg(min+max for daytime) or else it should be night average((min+max for nighttime)). Top doesn't depend on day or night. Any help appreciated</p>
  
  <p>Below is the login using java 7. need this using Java 8 features.</p>
  
  <pre><code>int dayavg=0;
          int nightavg = 0;
          int topavg=0;
          int day=0;
          int night = 0;
          int top=0;
      for(int i=0;i&lt;50;i++){
          JsonNode node = list.get(i);
          String dt = node.get("dt").textValue();
          if(dt.contains("06:00:00")|| dt.contains("09:00:00") || dt.contains("12:00:00") || dt.contains("15:00:00")){
              int val = node.get("core").get("min").asInt() + node.get("core").get("max").asInt();
              day = day + val;
          }
          if(dt.contains("18:00:00")|| dt.contains("21:00:00") || dt.contains("00:00:00") || dt.contains("03:00:00")){
              int val = node.get("core").get("min").asInt() + node.get("core").get("max").asInt();
              night = night + val;
          }
          int val = node.get("core").get("top").asInt();
          top = top + val;
      }
      topavg = top/50;
      dayavg = day/100;
      nightavg = night/100;
  </code></pre>