Вопрос Java.Java - toString неправильно печатает массив
Я хотел, чтобы распечатать массив с методу String, , но все это я получаю это:
[email protected]
[email protected]
Я знаю, что это указывает на точку, где массивы сохраняются, но как Я на самом деле распечатываю массивы с помощью метода toStinr?
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;
}
}
Это индивидуальный метод для тестирования:
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));
}
}
Вы не отметили вопрос на каком-либо языке. Я предполагаю, что это Java? – Mureinik
Да, извините, это! – marvin
Вы переопределили метод toString() в своем классе Fifo? – Christopher