I'm trying the following
List <String> enrolling = new ArrayList<String>();
String name;
enrolling.offer(name);
I'm trying the following
List <String> enrolling = new ArrayList<String>();
String name;
enrolling.offer(name);
The offer(E e)
method is not used with a list. The offer(E e)
method means offering a new element to a Queue
with a content limitation. The Queue
can reject the offer, returning false
.
For the reason that ArrayList
is a list (without limited capacity) and not a queue, offer
is not implemented in lists.
In List
you can use add(E e)
to add elements of type E
.
To use a queue, you use:
// construimos una cola con tamaño 10 elementos max
Queue<String> enrolled = new ArrayBlockingQueue<String>(10);
String name = "fulanito";
if (enrolled.offer(name)){
// el nuevo elemento fue acceptado, trabajemos con eso
} else {
// la cola estaba llena, así el elemento no fue aceptado.
// podriamos hacer algo como:
try{
enrolled.put(name); // put espera hasta que queda espacio en la cola
} catch (InterruptedException e){
// todavía no logremos y más encima fuimos interumpido
}
}
There are a variety of queue implementations for a multitude of uses, check the Queue
interface for references to specific implementations.