I'm learning from the Caelum workbooks data structures, and I started to see Liagada Lists, I followed all the code that it offers, step by step and I understood the logic of the list chained, but what I did not understand was this line of code:
System.out.println(lista); // lista é um objeto to tipo ListaLigada
That has output the array of strings:
[Paulo, Rafael]
I do not understand, because in my code the output that it gives is only the name of the class + the hascode of the object. Someone explain to me what happened ??? All the code to avoid bureaucracy is there:
public class Celula {
private Celula proxima;
private Object elemento;
public Celula(Celula proxima, Object elemento) {
this.proxima = proxima;
this.elemento = elemento;
}
public Celula(Object elemento) {
this.elemento = elemento;
}
public void setProxima(Celula proxima) {
this.proxima = proxima;
}
public Celula getProxima() {
return proxima;
}
public Object getElemento() {
return elemento;
}
}
The LinkedList class:
public class ListaLigada {
private Celula primeira;
private Celula ultima;
public void adiciona(Object elemento) {}
public void adiciona(int posicao, Object elemento) {}
public Object pega(int posicao) {return null;}
public void remove(int posicao){}
public int tamanho() {return 0;}
public boolean contem(Object o) {return false;}
}
The test code:
public class TesteAdicionaNoFim {
public static void main(String[] args) {
ListaLigada lista = new ListaLigada();
lista.adiciona("Rafael");
lista.adiciona("Paulo");
System.out.println(lista);
}
}
NOTE: I DO THE SAME CODE, EQUAL. EVERY LINE EXACTLY THE SAME WITH CAELUM'S APOSTILA