StackPWRequirmentsAreCrazy StackPWRequirmentsAreCrazy - 1 month ago 11
Java Question

How to iterate elements of an integer arraylist in Java

I understand that when you iterate a regular array element it is like so:

int[] counter = new int[10];

for loop{
counter[i] = 0;

when button clicked{
counter[0]++; //For example

However I'm not understanding how to iterate through elements of an arraylist. If someone could help me understand I'll be appreciative. Thanks!


The easiest way would be to use a for each loop

for(int elem : yourArrayList){
   elem;//do whatever with the element