Java,在方法中返回列表后如何打印列表元素?

时间:2019-06-05 15:00:38

标签: java list arraylist return

我想在列表中打印笔记本电脑(我刚刚在Notebook中写过)的详细信息。

我不知道如何在返回列表时打印列表元素。

class Notebook {
    String name;
    String CPU;
    double weight;
    int price;

    public Notebook(String name, String CPU, double weight, int price) {
        this.name = name;
        this.CPU = CPU;
        this.weight = weight;
        this.price = price;
    }
}

class LiberalArts{
    public List<Notebook> LA() {
    List<Notebook> list = new ArrayList<Notebook>();

    list.add(new Notebook("LG", "i3", 0.94, 1330000));
    list.add(new Notebook("Samsung", "i3", 1.34, 665000));

    return list;
    }
}

public class Main {
    public static void main(String[] args) {
        List<Notebook> TOP2 = new LiberalArts().LA();
        System.out.println(TOP2);
    }

}

输出:

[Notebook @ 66d33a,Notebook @ 7cf10a6f]

我想他们正在打印对象的地址,但是我不确定...

我想要这样的结果:

LG: i3, 0.94, 1339999

Samsung: i3, 1.34, 665000

请帮助!!!

0 个答案:

没有答案