如何检索和打印以下数据

问题描述 投票:-2回答:1

arraylist

我有这种格式的数据,它是对象itemdata的数组列表。

static class itemData{
    private String itemName;
    private int quantity;
    private double price;
    private int couponCode;
    private int couponId;
  }
  public List<itemData> itemList = new ArrayList<>();

下面是我存储数据的方式

 public couponInterface addItems(String itemName, int quantity, double price,
                                  int couponCode, int couponId) {

    itemData t = new itemData();
    t.itemName = itemName;
    t.quantity = quantity;
    t.price = price;
    t.couponCode = couponCode;
    t.couponId = couponId;
    itemList.add(t);
    return this;
  }

我如何检索数据并打印?

当前输出显示-couponAbstract $ itemData @ 31f924f5

java
1个回答
0
投票

以下是成功打印对象的方法。

不覆盖toString,并接受它提供的输入。 (您当前正在做什么)

覆盖java.lang.Object.toString();是另一个。 (只需将toString方法放在您的类中的任何位置,当您的类是一个对象时该方法会返回字符串)

通过各种方式收集变量并将其打印出来。

© www.soinside.com 2019 - 2024. All rights reserved.