“java foreach arraylist” Réponses codées

java foreach arraylist

// Java Program Demonstrate forEach()
// method of ArrayList
  
import java.util.*;
public class GFG {
  
    public static void main(String[] args)
    {
        // create an ArrayList which going to
        // contains a list of Numbers
        ArrayList<Integer> Numbers = new ArrayList<Integer>();
  
        // Add Number to list
        Numbers.add(23);
        Numbers.add(32);
        Numbers.add(45);
        Numbers.add(63);
  
        // forEach method of ArrayList and
        // print numbers
        Numbers.forEach((n) -> System.out.println(n));
    }
}
Prickly Piranha

java foreach arraylist

forEach() method
@Override
public void forEach(Consumer<? super E> action) 
{
    Objects.requireNonNull(action);
 
    final int expectedModCount = modCount;
 
    @SuppressWarnings("unchecked")
    final E[] elementData = (E[]) this.elementData;
    final int size = this.size;
    for (int i=0; modCount == expectedModCount && i < size; i++) {
        action.accept(elementData[i]);
    }
    if (modCount != expectedModCount) {
        throw new ConcurrentModificationException();
    }
}
Prickly Piranha

Réponses similaires à “java foreach arraylist”

Questions similaires à “java foreach arraylist”

Plus de réponses similaires à “java foreach arraylist” dans Java

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code