“Java foreach ArrayList” Code-Antworten

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

Ähnliche Antworten wie “Java foreach ArrayList”

Fragen ähnlich wie “Java foreach ArrayList”

Weitere verwandte Antworten zu “Java foreach ArrayList” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen