-4

arraylist

I have data in this format, its a arraylist of object 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<>();

below fuction is how i am storing the data

 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;
  }

how do i retrieve the data and print it?

the current output shows - couponAbstract$itemData@31f924f5

ajay singh
  • 19
  • 4

1 Answers1

-1

Here are ways to successfully print your object.

Not overriding toString, and accepting the input it gives. (What you are currently doing)

Overriding java.lang.Object.toString(); is another. (Just put a toString method anywhere in your class that returns string as your class is an object)

Gathering your variables by various means and printing them off.

FailingCoder
  • 757
  • 1
  • 8
  • 20