Java ArrayBlockingQueue forEach() 方法

2025 年 1 月 7 日 | 阅读 3 分钟

Java ArrayBlockingQueue 类的 forEach() 方法会为 Iterable 的每个元素执行指定的动作,直到所有元素都被处理完毕或动作抛出异常。

语法

参数

action - 这是要为每个元素执行的动作。

指定者:

ArrayBlockingQueue 类的 forEach() 方法由 Iterable<E> 接口中的 forEach() 方法指定。

抛出

如果定义的 action 为 null,则 forEach() 方法会抛出 NullPointerException。

示例 1

输出

[Reema, Rahul, Rita, Ramesh]

Printing the queue with the help of foreach loop: 
Reema
Rahul
Rita
Ramesh

示例 2

输出

1.Roll No. =  15cs1029
  College =  MVN University
  Name = Reema

2.Roll No. =  15cs1010
  College =  MVN University
  Name = Geetanjali

3.Roll No. =  17cs1029
  College =  MR University
  Name = Vineet

4.Roll No. =  15cs1011
  College =  MVN University
  Name = Himanshu

示例 3

输出

1 Lower case = aman
  Upper case = AMAN

2 Lower case = bhavika
  Upper case = BHAVIKA

示例 4

输出

71018
8000
1178
1190
Max number = 71018
Min number = 1178