I have the following code in c++, trying to convert it to java code
The code snippets below shows what I've tried, but its not working
C++ vector<vector<string>> ans; ans.push_back(vector<string>()); for(int k = i, sum = 0; k < n && sum < l[j] ; ++k) { sum += (int) w[k].size(); ans.back().push_back(w[k]); Java static Vector<Vector<String>> ans = new Vector<Vector<String>>(); ans.add(new Vector()); for(int k = i, sum = 0; k < n && sum < l[j] ; ++k) { sum += (int) w[k].length(); ans.add(w[k]); ans.lastElement().add(w[k]); fixes it