I have my Integer data in Array Lists of Arrays Lists and I want to convert that data to Lists of List format. How can I do it?
public List<List<Integer>> subsetsWithDup(int[] nums) {
ArrayList<ArrayList<Integer>> ansList = new ArrayList<ArrayList<Integer>>();
String arrStr = nums.toString();
ArrayList<Integer> tempList = null;
for(int i = 0 ; i < arrStr.length()-1 ; i++){
for(int j = i+1 ; j<arrStr.length() ; j++){
tempList = new ArrayList<Integer>();
tempList.add(Integer.parseInt(arrStr.substring(i,j)));
}
if(!ansList.contains(tempList)){
ansList.add(tempList);
}
}
return ansList;
}
Listis the base class ofArrayList,so you can either writeList<ArrayList<Integer>> cc = new ArrayList<ArrayList<Integer>>()where your generic typeArrayList<Integer>has to be same.List<List<Integer>> listList = new ArrayList<>(arrayLists);ArrayList<ArrayList<Integer>>is not aList<List<Integer>>