title: get mot common ip from log file (optimization)
body: <p>I have to get the most common ip from an logfile,
   I have a working method but I need some help with optimizing it/ I have to replace som passages with streams. Can you guys help me please ?</p>
  
  <pre><code>  private static String mostCommonIp(String fileName) throws IOException
  {
      Map&lt;String, Long&gt; ipAppearanceCount = new HashMap&lt;&gt;();
      String commonMostIp ="";
      List&lt;String&gt; lines = Files.lines(Paths.get(fileName))
              .collect(Collectors.toList());
  
      List&lt;String&gt; ipAddresses = lines
              .stream()
              .map(line -&gt; line.replaceAll("[ ]+", " ").split(" ")[2])
              .collect(Collectors.toList());
  
      for (int i = 0; i &lt; ipAddresses.size(); i++) {
          if (!ipAppearanceCount.containsKey(ipAddresses.get(i))){
              ipAppearanceCount.put(ipAddresses.get(i), (long) 1);
          }else{
              ipAppearanceCount.put(ipAddresses.get(i),
  ipAppearanceCount.get(ipAddresses.get(i))+1);
          }
      }
  
      Comparator&lt;? super Entry&lt;String, Long&gt;&gt; maxValueComparator =  
  Comparator.comparing(Entry::getValue);
  
      Optional&lt;Entry&lt;String, Long&gt;&gt; maxValue = ipAppearanceCount.entrySet()
              .stream().max(maxValueComparator);
  
      return String.valueOf(maxValue);
  }
  </code></pre>
  
  <p><a href="https://drive.google.com/open?id=1XmbyRWMEfL0monAmK8rD1X5jE1moNsWB" rel="nofollow noreferrer">Here is the log file</a></p>