Я пытаюсь вставить список целых чисел в другой список, но кажется, что я ошибаюсь, мой вывод не подходит, кто-нибудь может помочь? Вы также можете комментировать http://goo.gl/xdLP9HСписок List, но по результату не подходит
public class ListInsideList {
public static void main(String[] args) {
List<List<Integer>> newList = new ArrayList<List<Integer>>();
List<Integer> tempList = new ArrayList<Integer>();
List<Integer> originalList = new ArrayList<Integer>();
for (int i = 1; i <= 10; i++) {
originalList.add(i);//adding values to list
}
for(Integer value : originalList){
tempList.add(value);
if(tempList.size()==5)
{
newList.add(tempList);
System.out.println("iteration:"+newList);
tempList.clear();//clearing list
}
}
System.out.println("final:"+newList);
}
}
Выход:
iteration:[[6, 7, 8, 9, 10], [6, 7, 8, 9, 10]]
final :[[], []]
required is:iteration:[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
final:[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
Кстати, если мой ответ действительно решить, это вежливо, чтобы пометить его как «принято» , Благодарю. – Stewart