title: Sum of intervals in Java
body: <p>I am stuck on this kata in CodeWars and I have tried for a long time, like for a week or so for one kata. If you want a description of my question, go <a href="https://www.codewars.com/kata/52b7ed099cdc285c300001cd" rel="nofollow noreferrer">here</a>. </p>
  
  <p>This is my code, if you believe me, there are <strong>lots of bugs</strong> in it. Can someone please help me out?</p>
  
  <pre><code>public static int sumIntervals(int[][] intervals) {
      int sum = 0;
      int[] currentLargeInterval = {intervals[0][0], intervals[0][0]};
      ArrayList&lt;int[]&gt; addedIntervals = new ArrayList&lt;&gt;();
      ArrayList&lt;int[]&gt; arrays = new ArrayList&lt;&gt;();
      addAll(arrays, intervals);
      ArrayList&lt;int[]&gt; removed = new ArrayList&lt;&gt;();
      for (int i = 0; i &lt; arrays.size(); i++) {
          if (i &gt; 0) {
              if (arrays.get(i - 1)[1] &gt;= arrays.get(i)[0] &amp;&amp; arrays.get(i - 1)[1] &lt; arrays.get(i)[1]) {
                  removed.add(arrays.get(i));
                  currentLargeInterval[1] = arrays.get(i)[1];
              } else {
                  addedIntervals.add(currentLargeInterval);
                  currentLargeInterval = new int[]{arrays.get(i - 1)[0], arrays.get(i - 1)[0]};
              }
          }
      }
      addedIntervals.add(currentLargeInterval);
      arrays.removeAll(removed);
      arrays.addAll(addedIntervals);
      for (int[] a : arrays) {
          System.out.println(Arrays.toString(a));
      }
      return sum;
  }
  </code></pre>