Inserts the specified element at the tail of this queue if it is possible to do so immediately without exceeding the
queue's capacity, returning
true
upon success and
false
if this queue is full.
Inserts the specified element at the tail of this queue, waiting up to the specified wait time for space to become
available if the queue is full.
add() method will throw an exception if Queue is full:

package com.logicbig.example.arrayblockingqueue;
import java.util.concurrent.ArrayBlockingQueue;
public class OfferExample2 {
public static void main(String... args) {
ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<>(3);
for (int i = 0; i < 5; i++) {
try {
boolean b = q.add(i);
System.out.println(b);
} catch (Exception e) {
System.out.println(e);
}
}
}
}
Output
true
true
true
java.lang.IllegalStateException: Queue full
java.lang.IllegalStateException: Queue full
JDK 25

package com.logicbig.example.arrayblockingqueue;
import java.time.LocalTime;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
public class OfferExample3 {
public static void main(String... args) throws InterruptedException {
ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<>(3);
for (int i = 0; i < 5; i++) {
boolean b = q.offer(i, 1, TimeUnit.SECONDS);
System.out.println("offer succeeded: " + b);
System.out.println("time: " + LocalTime.now());
System.out.println("queue: " + q);
System.out.println("remaining capacity: " + q.remainingCapacity());
System.out.println("---");
}
}
}
Output
offer succeeded: true
time: 15:17:51.194147900
queue: [0]
remaining capacity: 2
---
offer succeeded: true
time: 15:17:51.194691100
queue: [0, 1]
remaining capacity: 1
---
offer succeeded: true
time: 15:17:51.194691100
queue: [0, 1, 2]
remaining capacity: 0
---
offer succeeded: false
time: 15:17:52.196073400
queue: [0, 1, 2]
remaining capacity: 0
---
offer succeeded: false
time: 15:17:53.198135
queue: [0, 1, 2]
remaining capacity: 0
---
JDK 25