“Java foreach Arraylist” Respostas de código

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

Respostas semelhantes a “Java foreach Arraylist”

Perguntas semelhantes a “Java foreach Arraylist”

Mais respostas relacionadas para “Java foreach Arraylist” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código