I am new to programming and trying to add object every time object created in list<>.
Customer obj = new Customer(name="abc",price=23);
Customer obj = new Customer(name="efg",price=45);
I want the price and name to add list and would like to sord price using Icomparable interface. Can someone explain it please, Thank You
As per what i understood from your question, you can add a static List into your Customer class and add the price into your list inside the constructor. So every time you create an object of the class, the price will be added to your list.
Customer Class -
When you are trying to print -