title: Vector conversion from c++ to java
body: <p>I have the following code in c++, trying to convert it to java code</p>
  
  <p>The code snippets below shows what I've tried, but its not working</p>
  
  <pre class="lang-cpp prettyprint-override"><code>C++
  vector&lt;vector&lt;string&gt;&gt; ans;
  ans.push_back(vector&lt;string&gt;());
  for(int k = i, sum = 0; k &lt; n &amp;&amp; sum &lt; l[j] ; ++k) {
          sum += (int) w[k].size();
          ans.back().push_back(w[k]);
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>Java
  static Vector&lt;Vector&lt;String&gt;&gt; ans = new Vector&lt;Vector&lt;String&gt;&gt;();
  ans.add(new Vector());
  for(int k = i, sum = 0; k &lt; n &amp;&amp; sum &lt; l[j] ; ++k) {
          sum += (int) w[k].length();
          ans.add(w[k]);
  </code></pre>
  
  <pre><code>ans.lastElement().add(w[k]); fixes it
  </code></pre>