I'm trying to input a variable into an ArrayList and then add all the elements. How can i do that? The code I tried is below. Thanks.
ArrayList<String> aListNumbers = new ArrayList<String>();
int abc = 23;
aListNumbers.add("abc");
aListNumbers.add("2");
aListNumbers.add("3");
//Java ArrayList Sum All Elements
int sum = 0;
for(int i=0; i < aListNumbers.size(); i++){
sum = sum + Integer.parseInt(aListNumbers.get(i));
}
System.out.println("Sum of all elements of ArrayList is " + sum);