title: Why am I getting an AssertionError when the expected and actual look identical?
body: <p>I'm trying to answer the following question from <em>Cracking the Coding Interview</em>. The code below is part of a project on GitHub, <a href="https://github.com/dishbreak/cracking-coding/blob/9ab93822af175f2673ce831a59a4450916838b06/src/com/dishbreak/cci/trees_and_graphs/GenericBinaryTree.java" rel="nofollow noreferrer">here</a>.</p>
  
  <blockquote>
    <p>Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (i.e., if you have a tree with depth D, you’ll have D linked lists).</p>
  </blockquote>
  
  <p>Being a good little developer, I wrote a unit test to check this. </p>
  
  <pre><code>@Test
  public void testGetValuesAtEachLevel() {
      Integer[] treeValues = {
              1, 2, 3, 4, 5,
              6, 7, 8, 9, 10,
              11, 12, 13, 14, 15
      };
  
      tree = new GenericBinaryTree&lt;&gt;(treeValues);
  
      Integer[][] expectedArray = {
              { 1 },
              { 2, 3 },
              { 4, 5, 6, 7 },
              { 8, 9, 10, 11, 12, 13, 14, 15 }
      };
  
      List&lt;List&lt;Node&lt;Integer&gt;&gt;&gt; expectedList = new ArrayList&lt;&gt;(4);
      for (Integer[] level : expectedArray) {
          List&lt;Node&lt;Integer&gt;&gt; list = new LinkedList&lt;&gt;();
          for (Integer value : level) {
              list.add(new Node&lt;&gt;(value));
          }
          expectedList.add(list);
      }
  
      assertEquals(expectedList, tree.getValuesAtEachLevel());
  }
  </code></pre>
  
  <p>And here's the code.</p>
  
  <pre><code>List&lt;List&lt;Node&lt;T&gt;&gt;&gt; getValuesAtEachLevel() {
      List&lt;List&lt;Node&lt;T&gt;&gt;&gt; results = new ArrayList&lt;&gt;();
  
      List&lt;Node&lt;T&gt;&gt; firstLevel = new LinkedList&lt;&gt;();
      firstLevel.add(getRoot());
      results.add(firstLevel);
  
      loadAtLevel(results, 1);
  
      return results;
  }
  
  private void loadAtLevel(List&lt;List&lt;Node&lt;T&gt;&gt;&gt; list, int level) {
      List&lt;Node&lt;T&gt;&gt; levelList = new LinkedList&lt;Node&lt;T&gt;&gt;();
  
      for (Node&lt;T&gt; node : list.get(level - 1)) {
          if (node.left() != null) levelList.add(node.left());
          if (node.right() != null) levelList.add(node.right());
      }
  
      if (levelList.isEmpty()) return;
  
      level++;
      list.add(levelList);
      loadAtLevel(list, level);
  }
  </code></pre>
  
  <p>Imagine my surprise when the unit test fails with the following error:</p>
  
  <pre><code>java.lang.AssertionError: expected: 
  java.util.ArrayList&lt;[[1], [2, 3], [4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14, 15]]&gt; but was: 
  java.util.ArrayList&lt;[[1], [2, 3], [4, 5, 6, 7], [8, 9, 10, 11, 12, 13, 14, 15]]&gt;
  </code></pre>
  
  <p>The string representations are identical, so I can't really figure out what happened here. As a matter of fact, if I change the assertion to this, the test passes:</p>
  
  <pre><code>    assertEquals(expectedList.toString(), tree.getValuesAtEachLevel().toString());
  </code></pre>
  
  <p>I'm getting the sense I'm about to learn something awfully valuable about interfaces and objects. What did I do wrong here? </p>