In the method queueAnalysis
, when I send to print System.out.println("Original: " + queue + "\n");
, System.out.println("colados: " + names + "\n");
and
System.out.println("Cola final: " +queue);
, gives me as output direcciones de memoria
, null
and direcciones de memoria
, and try to apply a iterator
and apply a casting of type class Customer
but still keeps giving memory addresses as output. Why ?,
How can I solve the problem?
class Customer {
String name;
int ticket;
Customer(String name, int ticket) {
this.name = name;
this.ticket = ticket;
}
String getName() {
return name;
}
int getTicket() {
return ticket;
}
}
public class Main {
public static void main(String[] args) {
Queue<Customer> queue = new LinkedList<>();
queue.add(new Customer("a1", 1));
queue.add(new Customer("a2", 2));
queue.add(new Customer("a3", -1));
queue.add(new Customer("a4", -1));
queueAnalysis(queue);
}
public static void queueAnalysis(Queue<Customer> queue) {
System.out.println("Original: " + queue + "\n");
String names[] = null;
int cant = 0;
int tam = queue.size();
for (int i = 0; i < tam; i++) {
if (queue.peek().getTicket() == -1) {
names[i] = queue.peek().getName();
cant++;
queue.poll();
}
}
System.out.println("colados: " + names + "\n");
System.out.println("Cola final: " +queue);
//Customer c;
for (Iterator it = queue.iterator(); it.hasNext();) {
System.out.println((Customer) it.next());
}
}
}