title: adding elements to the ArrayList nested inside another Arraylist
body: <p>I have nested ArrayList that looks like that in Java:</p>
  
  <pre><code>myArrayList = [element1, element2, [element3]] 
  </code></pre>
  
  <p>I would like to add elements so the ArrayList will look like that:</p>
  
  <pre><code>myArraylist = [element1, element2, [element3, element4, element5]] 
  </code></pre>
  
  <p>I tried to use; </p>
  
  <pre><code>myArrayList.get(2).add(elemet4);
  myArrayList.get(2).add(elemet5);
  </code></pre>
  
  <p>but as a result I got:</p>
  
  <pre><code>myArraylist = [element1, element2, [element3], element4, element5] 
  </code></pre>
  
  <p>Any hints how to resolve that will be much appreciated.</p>
  
  <p>edit:
  My bad, I should have attached Java code and avoid misleading you guys. Anyway here it is:</p>
  
  <pre><code>ArrayList&lt;ArrayList&lt;String&gt;&gt; finalArray = new ArrayList&lt;ArrayList&lt;String&gt;&gt;();
  ArrayList&lt;String&gt; finalArrayTempCopy = new ArrayList&lt;String&gt;();
  ArrayList&lt;Integer&gt; transactionTemp = new ArrayList&lt;Integer&gt;();
  
  private ArrayList&lt;Integer&gt; addTransaction(){
  
          System.out.println("Enter transaction amount:");
          int amount = scanner.nextInt();
          scanner.nextLine();
          transactionTemp.add(Integer.valueOf(amount)); 
          return transactionTemp;
  }
  private int searchName(String name){
          int indexImienia = customerName.indexOf(name);
          return indexImienia;
      }
  
  public void sumUp(){
          String name = "Tom";
          String branch = "First";
          int indexImienia = searchName(name);
          String transactionsAsString = transactionTemp.toString();   
          finalArrayTemp.add(name);
          finalArrayTemp.add(branch);
          finalArrayTemp.add(transactionsAsString);
          finalArrayTempCopy = new ArrayList&lt;String&gt;(finalArrayTemp);
  
          finalArray.add(indexImienia, finalArrayTempCopy);
  }
  </code></pre>
  
  <p>Later in the code if I want to add single transaction I use the following method </p>
  
  <pre><code>public void addSingleTransaction(){
  int indexImienia = 0;
  int amount =20;
  finalArray.get(indexImienia).add(2, String.valueOf(amount));
  }
  </code></pre>
  
  <p>Editing my post I realised that the problem might lie with converting ArrayList into string and adding it to finalArray as string. Anyway, I will be grateful for your insight.</p>