Java question.
I wanted to print out an array with the to String method, but all I get is this:
fifo.Fifo@2a139a55
fifo.Fifo@15db9742
I know that this points to the point where the arrays are saved, but how can I actually print out the arrays with the toStinr method?
import java.util.ArrayList;
public class Fifo {
private ArrayList <Object> list;
public Fifo() {
this.list = new ArrayList <Object>();
}
public void push(Object obj) {
list.add(obj);
}
public ArrayList getList() {
return this.list;
}
public Object pull() {
if (list.isEmpty()) {
System.out.println("leer");
return null;
}
Object o = list.get(0);
list.remove(0);
return o;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (o.getClass() == this.getClass()) {
Fifo other = (Fifo) o;
ArrayList otherList = other.getList();
if (otherList.size() == this.getList().size()) {
boolean sameObjects = true;
for (int i = 0; i < list.size(); i++) {
if (!list.get(i).equals(otherList.get(i))) {
sameObjects = false;
}
}
if (sameObjects)
return true;
}
}
return false;
}
public Fifo clone() {
Fifo cloneObj = new Fifo();
for (int i = 0; i < this.list.size(); i++) {
cloneObj.push(this.list.get(i));
}
return cloneObj;
}
}
This is the seperate method for testing:
import java.util.*;
public class Aufgabe {
public static void main(String [] args){
Fifo test = new Fifo();
Fifo test2;
test.push(1234);
test.push("Hallo");
test.push(5678);
test.push("du da");
test.pull();
System.out.println(test.toString());
test2=test.clone();
System.out.println(test2.toString());
System.out.println(test2.equals(test));
}
}