Help to do this, I recently began to learn collections and a little do not understand how to do it. I have a class ProductSearchSrvice (list of online stores)
class ProductSearchSrvice { private String name; public ProductSearchSrvice(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "Online store {" + "name = '" + name + '\'' + '}'; } } And there is a class where these classes are displayed.
public class Lab10 { public static void main(String[] args){ List<ProductSearchSrvice> list = new ArrayList<>(); ProductSearchSrvice shop_1 = new ProductSearchSrvice("Rozetka"); ProductSearchSrvice shop_2 = new ProductSearchSrvice("OLX"); ProductSearchSrvice shop_3 = new ProductSearchSrvice("HIKVISION"); list.add(shop_1); list.add(shop_2); list.add(shop_3); ProductSearchSrvice shop_1FromCollection = list.get(0); ProductSearchSrvice shop_2FromCollection = list.get(1); ProductSearchSrvice shop_3FromCollection = list.get(2); System.out.println(shop_1FromCollection); System.out.println(shop_2FromCollection); System.out.println(shop_3FromCollection); } } I can’t understand a bit how to determine the name of the store in the online store class, if it is in another class, and how then to display elements of this class on the screen.
ProductSearchSrviceis no service at all, it's just an entity, I would call it just aStore. It is not clear what needs to be done - Oleksiy Morenets