I have an arraylist with the following numbers added to it.
ArrayList<Integer> nums = new ArrayList<>();
nums.add(4);
nums.add(19);
nums.add(32);
nums.add(-8);
Then I am using the following code to iterate through the list and sum them before printing.
sum += IntStream.range(0, nums.size()).sum();
System.out.println(sum);
It is printing out a value of 6. Does anyone know what is happening or can someone explain what I am doing wrong here? Thank you for your time and if there is anything I can add for clarification, please don't hesitate.