I was doing a little coding challenge at work and we were required to perform quite a bit of business logic that result in a List of Lists of Integers. I had the required information in an ArrayList of ArrayList of Integers, but could never figure out how to convert it to the correct return type.
Also many variations on using T or Object as they types. I've searched stack overflow and there are many similar problems, but none that give me a straight answer; they're more conceptual.
Problem to answer: The output MUST be a
List<List<Integer>> (not negotiable).
Given an existing:
ArrayList<ArrayList<Integer>> **currentArrayList** HOW do you convert that to a List<List<Integer>>.
I no longer need the code, but It's going to drive me nuts to be able to do all the logic but not a simple type conversion.
List<List<Integer>> returnList(){
ArrayList<ArrayList<Integer>> currentArrayList = new ArrayList<ArrayList<Integer>>();
ArrayList<Integer> innerList = new ArrayList<Integer>();
innerList.add(new Integer(123));
currentArrayList.add(innerList);
List<List<Integer>> newList = ????
// ??Logic to copy over currentArrayList into newList???
return newList;
}
List<List<Integer>> currentArrayList = new ArrayList<>();List<ArrayList<Integer>>isn't aList<List<Integer>>.Objectto a specific subclass wouldn't be (though not for the same reasons).List<List<Integer>> newList = new ArrayList<>(currentArrayList);