title: How to increase the performance with Java ArrayList
body: <p>I'm using a huge ArrayList with the code bellow</p>
  
  <pre><code>public final List&lt;MyClass&gt; list = new ArrayList&lt;&gt;();
  
  public void update(MyClass myClass) {
  int i;
  for (i=0; i &lt; list.size(); i++) {
          if (myClass.foo(list.get(i))) {
              list.set(i, myClass);
              break;
          }    
      }    
      if (i == list.size()) {    
          list.add(myClass);    
      }    
  }
  </code></pre>
  
  <p>The list is extremely large. There is something else that I can do to increase the performance with this scenario? Maybe using some Java 8 feature, replacing ArrayList or something like that.</p>
  
  <p>Another code that is taking too long to run related this List is the code bellow:</p>
  
  <pre><code>public List&lt;MyClass&gt; something(Integer amount) {
  list.sort((m1, m2) -&gt; Double.compare(m2.getBar(), m1.getBar()));
  return list.stream()
          .limit(amount)
          .collect(Collectors.toList());
  }
  </code></pre>
  
  <p>Any help is welcome, thank you all</p>