Im using arraydeque to create a list of elements and pass their parameters (Elements are classes)
ArrayDeque<Item> Items= new ArrayDeque<Item>();
But I have a problem with java ArrayDeque. Perhaps there are ways to add multiple items at once. For instance. I want to add at the same time TableType and colourOfTable to ArrayDeque.
In C ++, I could do this with this
vector<Item>Items Items.push_back(Item("CoffeeTable", "brown"));
I want to do the same with Java. Instead of creating a new object for each element, like:
ArrayDeque<Item> Items = new ArrayDeque<Item>(); Item obj = new Item("CoffeTable", "brown"); Items.add(obj); Item obj1 = new Item("DinnerTable", "Black"); Items.add(obj1);
But instead of obj I want to add "CoffeTable", "brown" at the same time and with one line of code (for example, in the C ++ example) to the Items array.
I tried something like this
ArrayDeque<Item> Items= new ArrayDeque<Item>(); Items.add(Items("CoffeTable", "brown"));
But then an error occurred while creating the create method "Items (String, String)"
source share