-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
42 lines (31 loc) · 1.18 KB
/
Main.java
File metadata and controls
42 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.dj;
import java.util.ArrayList;
import java.util.Arrays;
record GroceryItem(String name, String type, int count){
public GroceryItem(String name){
this(name, "DAIRY",1);
}
@Override
public String toString(){
return String.format("%d %s in %s", count,name.toUpperCase(),type);
}
}
public class Main {
public static void main(String[] args) {
GroceryItem[] grocerArray = new GroceryItem[3];
grocerArray[0] = new GroceryItem("milk");
grocerArray[1] = new GroceryItem("apples", "PRODUCE", 6);
grocerArray[2] = new GroceryItem("oranges", "PRODUCE",5);
System.out.println(Arrays.toString(grocerArray));
ArrayList objectList = new ArrayList();
objectList.add(new GroceryItem("Butter"));
objectList.add("Yogurt");
ArrayList<GroceryItem> groceryList = new ArrayList<>();
groceryList.add(new GroceryItem("Butter"));
groceryList.add(new GroceryItem("milk"));
groceryList.add(new GroceryItem("orange","PRODUCE",5));
groceryList.set(0,new GroceryItem("apples","PRODUCE",6));
groceryList.remove(1);
System.out.println(groceryList);
}
}