title: Implementing List interface for CustomList in Java
body: <p>I need to create a custom list that adds elements in pairs. I copied a similar implementation and adjusted it as needed, but unfortunately, it doesn't work.</p>
  <pre><code>class PairStringList implements List&lt;String&gt; {
  
      private List list;
  
      public PairStringList() {
          list = new ArrayList();
      }
  
      @Override
      public boolean add(String s) {
          list.add(list.size(), s);
          list.add(list.size(), s);
          return true;
      }
  
  //other methods
  }
  </code></pre>
  <p>And I have this for testing my code so far.</p>
  <pre><code>public static void main(String[] args) {
          List&lt;String&gt; list = new PairStringList();
          list.add(&quot;1&quot;);
          list.add(&quot;2&quot;);
          list.add(&quot;3&quot;);
  
          for(int i = 0; i &lt; list.size(); i++) {
              String s = list.get(i);
              System.out.println(s);
          }
  
          list.add(4, &quot;0&quot;);
  
          for(int i = 0; i &lt; list.size(); i++) {
              System.out.println(list.get(i));
          }
      }
  </code></pre>
  <p>The problem is that when I call add method the size of the list increases by 2 as it should, but nothing is added and I get an array full of nulls.</p>